【发布时间】:2016-10-07 08:52:48
【问题描述】:
首先,所有第三方库都应该包装在 Angular 模块中,以便可以将其作为依赖项添加到其他 Angular 模块中。
例如
angular.module('lodash', [])
.factory('_', function($window) { return $window._;});
并将其注入其他模块,例如:
angular.module('myApp', ['lodash']);
问题是,第三方库应该在依赖列表的开始还是结束位置?
angular.module('myApp').controller(function($scope, _){});
VS
angular.module('myApp').controller(function(_, $scope){});
这两种情况都有效,但您对此有何看法?
提前谢谢你
【问题讨论】:
-
这应该与您在第三方库开始时所做的相同,然后是您的自定义脚本
-
这有什么关系? Angular 会注入服务/工厂,无论它位于何处或在哪里。
标签: angularjs dependency-injection angular-controller