Reputation: 115
I am new to AngularJs. While learning ,i am seeing these two types of controller declarations.
Can you guys just tell me the significance of each type mentioned below.
Type 1:
var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', ['$scope', function($scope) {
$scope.letter="A";
}]);
Type 2:
var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', [ function($scope) {
$scope.letter="A";
}]);
Upvotes: 0
Views: 3229
Reputation: 1891
In the first type (recommended type), the string "$scope"
is used for minification purposes - all arguments are shortend to one or two characters. Strings are not minified, therefore Angular will use this string when injecting to the controller. Look at this reference: https://stackoverflow.com/a/18782380/5954939
Upvotes: 1