AngularJS $ parse TypeError:对象不是函数 [英] AngularJS $parse TypeError: object is not a function

查看:64
本文介绍了AngularJS $ parse TypeError:对象不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将我的应用程序精简了,但是使用$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆