[英]Cannot read property '$scope' of undefined AngularJs Error
I am getting an error in my angularJS and I am not not sure why. 我的angularJS出现错误,我不确定为什么。 I am trying to use the $inject Property Annotation method described here: https://docs.angularjs.org/guide/di
我正在尝试使用此处描述的$ inject属性注释方法: https : //docs.angularjs.org/guide/di
I get the following error Uncaught TypeError: Cannot read property '$scope' of undefined on line 44 which is 我收到以下错误Uncaught TypeError:无法读取第44行未定义的属性'$ scope'
CarouselController.$inject['$scope'];
My App.JS looks like: 我的App.JS看起来像:
var bloxApp = angular.module('bloxApp', ['bloxApp.form', 'bloxApp.carousel']);
bloxApp.config(['$logProvider', function ($logProvider) {
$logProvider.debugEnabled(true);
}]);
My blox-app.js looks like this: (app.js is loaded first, blox-app.js loaded immediately following:) 我的blox-app.js看起来像这样:(首先加载app.js,随后立即加载blox-app.js :)
angular.module('bloxApp.common'[]);;angular.module('bloxApp').factory('lodash', ['$window', function (window) {
return window._;
}]);;(function () {
angular.module('bloxApp.form', []);
})();;(function () {
var FormController = function ($scope, $window, $http, _) {
$scope.choices = [{ id: 'choice1' }, { id: 'choice2' }, { id: 'choice3' }];
$scope.addNewPiece = function () {
var newItemNo = $scope.choices.length + 1;
$scope.choices.push({ 'id': 'choice' + newItemNo });
};
$scope.removePiece = function (int_id) {
var newItemNo = $scope.choices.id;
_.pull($scope.choices, _.find($scope.choices, { id: int_id }));
};
}
FormController.$inject = ['$scope', '$window', '$http', 'lodash'];
angular.module('bloxApp.form')
.controller('FormController', FormController);
})();
;;;(function () {
angular.module('bloxApp.carousel', []);
})();;(function () {
var CarouselController = function ($scope) {
$scope.slides = [
{
image: 'http://lorempixel.com/400/200/', text: 'hello'
},
{
image: 'http://lorempixel.com/400/200/food', text: 'hello'
},
{
image: 'http://lorempixel.com/400/200/sports', text: 'hello'
},
{
image: 'http://lorempixel.com/400/200/people', text: 'hello'
}
];
}
CarouselController.$inject['$scope'];
angular.module('bloxApp.carousel')
.controller('CarouselController', CarouselController);
})();
It should be CarouselController.$inject = ['$scope']
. 应该是
CarouselController.$inject = ['$scope']
。
You missed the =
so it's trying to access a property called $scope
on the property of $inject
on CarouselController
, rather than setting the $inject
property equal to ['$scope']
. 您错过了
=
因此它试图在CarouselController
上访问$inject
属性上的$scope
属性,而不是将$inject
属性设置为['$scope']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.