Is it necessary to inject $scope to a controller i

2019-03-01 02:50发布

This question already has an answer here:

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

1条回答
何必那么认真
2楼-- · 2019-03-01 03:06

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.

查看更多
登录 后发表回答