无法读取未定义的 AngularJs 错误的属性"$scope"



我得到一个错误在我的angularJS,我不知道为什么。我试图使用这里描述的$inject属性注释方法:https://docs.angularjs.org/guide/di

我得到以下错误Uncaught TypeError: Cannot read property '$scope' of undefined在第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);
})();

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

您错过了=,因此它试图访问CarouselController$inject属性上的$scope属性,而不是将$inject属性设置为['$scope']

最新更新