我在AngularJS中遇到此错误:
TypeError: Cannot call method 'apply' of undefined
at Object.$get.e.$emit (http://localhost/TestPortal/js/lib/angular.min.js:87:296)
at j (http://localhost/TestPortal/js/lib/angular.min.js:146:351)
at http://localhost/TestPortal/js/lib/angular.min.js:88:100
at Array.forEach (native)
at m (http://localhost/TestPortal/js/lib/angular.min.js:6:193)
at Object.$get.e.$broadcast (http://localhost/TestPortal/js/lib/angular.min.js:88:63)
at http://localhost/TestPortal/js/lib/angular.min.js:80:114
at k.promise.then.i (http://localhost/TestPortal/js/lib/angular.min.js:76:119)
at k.promise.then.i (http://localhost/TestPortal/js/lib/angular.min.js:76:119)
at http://localhost/TestPortal/js/lib/angular.min.js:76:352
在我的控制器中调用这行代码时:
function ClientController($scope, $routeParams, $location, StaticData, Client, IndustryFactory) {
$scope.$on('$viewContentLoaded', someMethod);
}
尝试下面也没有帮助,同样的错误:
ClientController.$inject = ['$scope', '$routeParams', '$location', 'StaticData', 'Client', 'IndustryFactory'];
答案 0 :(得分:1)
您需要在控制器中明确包含$scope
,以使其正常工作。
function ClientController($scope, $routeParams, $location, StaticData, Client, IndustryFactory) {
$scope.$on('$viewContentLoaded', someMethod);
}
ClientController.$inject = ['$scope', '$routeParams', '$location'];
答案 1 :(得分:1)
想出来。见修改后的代码:
$scope.$on('$viewContentLoaded', function() { someMethod() });
答案 2 :(得分:0)
我认为这是缩小代码的问题。如@jayaram所描述的那样注入依赖关系,或者使用[]
表示依赖关系并使用模块。请参阅Notes on Minification
here