AngularJs将来自单独文件的多个指令注入一个公共模块

问题描述 投票:2回答:2

有一个关于引用和注入指令到不同模块的问题。目标是将位于单独文件中的多个指令注入一个模块,然后将该通用模块注入其他位置。我有多个指令,在单独的文件中定义,例如:

define(['angular'], function (angular) {

angular.module('ngCustomDirective')
    .directive('ngCustomDirective', function () {
       ...
    });
});

在单独的文件中,我有:

define(['angular'], function (angular) {

angular.module('ngCustomDirective2')
    .directive('ngCustomDirective2', function () {
       ...
    });
});

之后,该指令在另一个模块(不同的文件)中被引用:

define(['angular','ngCustomDirective', 'ngCustomDirective2'], function (angular, ngCustomDirective, ngCustomDirective2) {

angular.module('directives', [ngCustomDirective, ngCustomDirective2]);

return 'directives';
});

接下来,这个'指令'模块被注入另一个模块。上面的代码不起作用。我在这里做错了什么?

angularjs angularjs-directive angularjs-scope
2个回答
1
投票

您可以尝试在单引号内注入模块,如下所示吗?

angular.module('directives',['ngCustomDirective','ngCustomDirective2']);


-1
投票

按照这个答案的指南来确切地说你需要做什么.. open link

© www.soinside.com 2019 - 2024. All rights reserved.