无法阅读财产' $ scope'未定义的AngularJs错误

时间:2015-05-23 21:35:20

标签: javascript angularjs

我的angularJS出错,我不确定原因。我正在尝试使用此处描述的$ inject Property Annotation方法:https://docs.angularjs.org/guide/di

我收到以下错误Uncaught TypeError:无法读取属性' $ scope'第44行的未定义是

CarouselController.$inject['$scope'];

我的App.JS看起来像:

var bloxApp = angular.module('bloxApp', ['bloxApp.form', 'bloxApp.carousel']);
bloxApp.config(['$logProvider', function ($logProvider) {
$logProvider.debugEnabled(true);
}]);

我的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);

})();

1 个答案:

答案 0 :(得分:2)

应该是CarouselController.$inject = ['$scope']

您错过了=,因此它试图在$scope $inject的{​​{1}}属性上访问名为CarouselController的媒体资源,而不是设置$inject媒体资源等于['$scope']