【问题标题】:Angular.js dependencies order for third party librariesAngular.js 第三方库的依赖顺序
【发布时间】: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


【解决方案1】:

在这种情况下,顺序并不重要。 Angularjs 会自动处理依赖关系之间的依赖关系。

【讨论】:

    猜你喜欢
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    相关资源
    最近更新 更多