Angularjs: Uncaught Referenceerror: Angular Is Not Defined App.js:1(anonymous Function):
I have moved my AngularJS test project into app.js, controllers.js and Services.js. After it my project is not running and not even a single page is being working properly. i have
Solution 1:
This is because you have mixed the array notation for injected dependencies in your controller and in your module.
Controller.js
'use strict';
var app = angular.module('app.controllers', []);
app.controller('CalculatorCtrl', ['$scope', '$http', 'CalculatorService', function($scope, $http, CalculatorService){
console.log('in CalculatorCtrl...');
$scope.doSquare = function() {
$scope.answer = CalculatorService.square($scope.number);
};
$scope.doCube = function() {
$scope.answer = CalculatorService.cube($scope.number);
};
}]);
UPDATE: Remove $scope
and CalculatorService
in functions doSquare
and doCube
, they are already included as dependencies in your controller. Updated version above.
Solution 2:
You can fix it by
'use strict';
var app = angular.module('app.controllers');
varCalculatorCtrl =function($scope, $http, CalculatorService){
console.log('in CalculatorCtrl...');
doSquare = function($scope, CalculatorService) {
$scope.answer = CalculatorService.square($scope.number);
}
doCube = function($scope, CalculatorService) {
$scope.answer = CalculatorService.cube($scope.number);
}
};
CalculatorCtrl.$inject = ['$scope', '$http', 'CalculatorService']; //old technique to add dependencies
app.controller('CalculatorCtrl', CalculatorCtrl);
Solution 3:
I got the same error:
Uncaught ReferenceError: getList is not defined
Note:In your case, the error says Angular is not defined, but for me, a function could not be find.
that was because I forgot a simple thing, my code was like this:
<aonclick="getList();"> Get List</a>
I called the Angular function by onclick
, and it should be ng-click
, in my case, I just needed to change that to this:
<ang-click="getList();"> Get List</a>
Post a Comment for "Angularjs: Uncaught Referenceerror: Angular Is Not Defined App.js:1(anonymous Function):"