AngularJS $ parse TypeError:对象不是函数 [英] AngularJS $parse TypeError: object is not a function
问题描述
我已经将我的应用程序精简了,但是使用$ parse时仍然出现此错误: TypeError:对象不是函数
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
怎么了?我想念什么?
似乎可以在此插件中正常工作: http://plnkr.co/edit/WrXv9hT5YA0xYcLLvyDb
解析可能与其他模块冲突吗?
Seems to work fine in this plunker: http://plnkr.co/edit/WrXv9hT5YA0xYcLLvyDb
Could parse be conflicting with some other module?
Weirder仍然-确实确实改变了$ scope.modal.on的值!即使它似乎早就死了...
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);
}]);
推荐答案
您以不正确的顺序传入了依赖项.该函数的依赖关系必须与数组中的顺序完全匹配.
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) {
如果在控制器声明中交换$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.
这篇关于AngularJS $ parse TypeError:对象不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!