3

I have stripped my app down to the bare bones but I keep getting this error when using $parse: TypeError: object is not a function

What is wrong? What am I missing?

Seems to work fine in this plunker: http://plnkr.co/edit/WrXv9hT5YA0xYcLLvyDb
Could parse be conflicting with some other module?

Weirder still - it actually does change the value of $scope.modal.on! Even though it appears to die before hand...

/* Controllers */

//var MyApp = angular.module('MyApp', ['ngSanitize', 'ui.bootstrap', 'ui.sortable']);
var MyApp = angular.module('MyApp', ['ngSanitize', 'ui.bootstrap']);


MyApp.controller('MyController', ['$scope', '$http', '$modal', '$parse', function($scope, $http, $parse, $modal, $log) {



    $scope.modal = { 
        open    : false,
        tplfile : null,
        toggle  : function(){ 
            this.open = !this.open; 
            if(this.open) angular.element('body').addClass('modal-open');
            else          angular.element('body').removeClass('modal-open');
        }   
    };

        var modal = $parse('modal.open');
        modal.assign($scope, true);

}]);
0

2 Answers 2

3

You passed in your dependencies in the incorrect order. The dependencies to the function have to match exactly the order in the array.

MyApp.controller('MyController', 
['$scope', '$http', '$modal', '$parse', function
($scope, $http, $parse, $modal, $log) {

If you swap $parse and $modal in your controller declaration, your error will go away. Also, you are missing $log, if you try to use that dependency you will get an error as well.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked, it was the order. And you won by about 30 secs ;)
2
['$scope', '$http', '$modal', '$parse', function($scope, $http, $parse, $modal,

The $parse and $modal are interchanged.

Please correct the order and it will work :)

It should be

MyApp.controller('MyController', ['$scope', '$http', '$modal', '$parse', '$log', function($scope, $http,  $modal, $parse, $log) {

1 Comment

You're totally right, that worked. But Claies edged you out by 30 secs. ;) Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.