有一个关于引用和注入不同模块的指令的问题。目标是将位于单独文件中的多个指令注入到一个模块中,然后将该通用模块注入到其他位置。我有多个指令,在分开的文件中定义的,例如:AngularJs从单独的文件注入多个指令到一个公共模块
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中有一种方法可以定义指令,而无需将模块指定为函数。然后我可以毫无问题地从其他模块中引用它。在我的代码中,我在模块的定义中遇到了一个问题:'angular.module('ngCustomDirective')'应该定义为'angular.module('ngCustomDirective',[])'或者现在,我试图避免在指令中定义模块定义。 –