0

I am getting an error in my angularJS and I am not not sure why. I am trying to use the $inject Property Annotation method described here: https://docs.angularjs.org/guide/di

I get the following error Uncaught TypeError: Cannot read property '$scope' of undefined on line 44 which is

CarouselController.$inject['$scope'];

My App.JS looks like:

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:)

    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 Answer 1

2

It should be 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'].

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I looked at that for hours and totally missed it.
@Joe No problem. Silly typos catch out everybody, sometimes just another pair of eyes help. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.