0

One method passes an array, the other a function; is there a difference between the two? Should one be used over the other depending on the situation? What's the point in naming all the variables twice?

Is "variable" the correct term for what's being passed in, or is there a more specific term for these particular types of variables in AngularJS?

config(['$routeProvider', function($routeProvider) {

vs

.config(function ($routeProvider) {
4

1 回答 1

1

如果您想在部署到生产环境之前缩小代码,请传入数组。

因为 minify 会更改参数的名称,并且 angular Dependency Injection 依赖于参数名称,所以如果它们被缩小(从 '$routeProvider' 到 'a')它不会识别它,这就是你添加数组的原因,因为缩小不会不要改变字符串。

他们基本上都做同样的事情,如果你不需要缩小不要使用数组方式,但通常你会......

关于“变量”术语,它更像是“可注入”而不是变量……因为它是 DI 用单例替换的东西,可以是函数、对象或字符串等……

于 2013-06-22T23:42:07.960 回答