3

Is there any difference between the following two code snippet? Both work.

1.

myApp.controller("myAppController", ["$scope", function($scope) {
// function body
}]);

2.

myApp.controller("myAppController", function($scope) {
// function body
});
coolgod
  • 539
  • 6
  • 9

1 Answers1

2

Well, difference will create during minfication. If you don't follow the step1 , minification will break your code.

Uglify Version of your 1st code

myApp.controller("myAppController",["$scope",function(o){}])

Uglify Version of your 2nd code

myApp.controller("myAppController",function(o){})

If you follow step 1 , Angular will find definition of o from injection.

But if you follow step 2 , Angular won't find definition of o from any source.

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80