本文介绍了有必要将$ scope注入到angularjs中的控制器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下两个代码段之间是否有区别?两者都可以.
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进行操作,则缩小会破坏您的代码.
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){}])
第二个代码的丑化版本
myApp.controller("myAppController",function(o){})
如果遵循步骤1,Angular将从注入中找到o
的定义.
If you follow step 1 , Angular will find definition of o
from injection.
但是,如果您按照步骤2进行操作,Angular将无法从任何来源找到o
的定义.
But if you follow step 2 , Angular won't find definition of o
from any source.
这篇关于有必要将$ scope注入到angularjs中的控制器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!