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";
}]);

1 Answer 1

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

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

Comments

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.