異なるモジュールに指令を参照したり注入したりする際に問題があります。目標は、別々のファイルにある複数の指令を1つのモジュールに注入し、その共通のモジュールを他の場所に注入することです。ディレクティブは、別のモジュール(別のファイル)で参照された後AngularJs別々のファイルから複数の指令を1つの共通モジュールに注入する
define(['angular'], function (angular) {
angular.module('ngCustomDirective2')
.directive('ngCustomDirective2', function() {
...
});
});
::、別のファイルに
define(['angular'], function (angular) {
angular.module('ngCustomDirective')
.directive('ngCustomDirective', function() {
...
});
});
私が持っている:私は、例えば別々のファイルで定義された複数のディレクティブを、持っている
define(['angular','ngCustomDirective', 'ngCustomDirective2'], function (angular, ngCustomDirective, ngCustomDirective2) {
angular.module('directives', [ngCustomDirective, ngCustomDirective2]);
return 'directives';
});
次に、この「指令」モジュールが別のモジュールに注入されます。上記のコードは動作しません。私はここで間違っていますか?
問題ではないこと、もう一つの問題があります。ディレクティブはモジュールなしで定義する必要があります。 AngularJsには、モジュールを関数として指定しないでディレクティブを定義する方法があります。それで、他のモジュールから問題なく参照できます。私のコードでは、モジュールの定義に問題がありました: 'angular.module( 'ngCustomDirective')'はangular.module( 'ngCustomDirective'、[]) 'として定義する必要があります。ディレクティブにモジュール定義を定義します。 –