这两种方式都可以工作,但是每种实现方法的实际区别是什么?我相信每种方法背后都有逻辑上的原因,我希望能够得到启示。
angular.module('app').controller('GeneralCtrl',
function($scope, $location, exampleService) {
$scope.variable = exampleService.getExampleVariable();
}
);
angular.module('app').controller('GeneralCtrl',
['$scope', '$location', 'exampleService', function($scope, $location, exampleService) {
$scope.variable = exampleService.getExampleVariable();
}]
);
这两者实际上有什么区别?何时使用它们有所不同?为什么?
答案:事实证明,后者可以进行缩小并且安全,因为缩小器会重命名参数名称,因此无法从它们的名称推断依赖关系,必须进行注释。