【问题标题】:Kind of base module in AngularAngular中的基本模块类型
【发布时间】:2015-11-17 08:22:27
【问题描述】:

我有一个角度模块,它有一些配置代码,例如:

angular.module('qrApp').config(['$httpProvider', '$sceDelegateProvider', function ($httpProvider, $sceDelegateProvider) {
    // configuring providers
}]);

qrApp.directive('fileModel', ['$parse', function ($parse) {
    // custom directive here
}]);

现在我需要另一个新模块,它具有相同的配置和指令设置,不重复代码但具有某种“基本”模块的最佳方法是什么,因此两者都可以从它继承,因此具有相同的设置。谢谢。

【问题讨论】:

    标签: angularjs inheritance config base


    【解决方案1】:

    您可以将通用代码放在单独的模块中,并将该模块添加到模块的依赖项列表中

    //common.js
    angular.module('common', []).config(...).directive(...);
    

    然后使用它

    angular.module('qrApp', ['common']);
    

    【讨论】:

    • 谢谢!简单明了的解决方案!您能否分享一些有关主题的链接以阅读以更好地了解我这样做时发生了什么?
    猜你喜欢
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    • 2017-12-06
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多