0

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";
}]);
Rajesh Choudhary
  • 115
  • 1
  • 3
  • 15

1 Answers1

1

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

Community
  • 1
  • 1
AranS
  • 1,871
  • 10
  • 22