I encountered an issue with my angularJS code and I'm unsure of the cause. I attempted to utilize the $inject Property Annotation method as detailed in this guide
The error message "Uncaught TypeError: Cannot read property '$scope' of undefined on line 44" pops up, which corresponds to:
CarouselController.$inject['$scope'];
This is how my App.JS file looks like:
var bloxApp = angular.module('bloxApp', ['bloxApp.form', 'bloxApp.carousel']);
bloxApp.config(['$logProvider', function ($logProvider) {
$logProvider.debugEnabled(true);
}]);
In my blox-app.js, you will find the following structure (app.js loads first, followed immediately by 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);
})();