2

there is a question regarding referencing and injecting directives into different modules. The goal is to inject multiple directives located in separate files into one module, and then inject that common module to other places. I have multiple directives, defined in separate files, for example:

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

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

in separate file, I have:

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

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

after that the directive is referenced in another module (different file):

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

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

return 'directives';
});

next, this 'directives' module is injected into another module. The code above doesn't work. What I'm doing wrong here?

n00dl3
  • 21,213
  • 7
  • 66
  • 76

2 Answers2

1

Can you try injecting the module within the single quote as below?

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

Immanuel Kirubaharan
  • 1,094
  • 1
  • 11
  • 17
  • that is not the problem, there is another issue. The directives should be defined without module. There is a way in AngularJs to define directives without module specified as a function. Then I can reference it from other modules without problem. In my code I had a problem in the definition of the module: `angular.module('ngCustomDirective')` should be defined as `angular.module('ngCustomDirective', [])` or now, I'm trying to avoid defining module definition in the directives. – Semen Shekhovtsov Apr 04 '17 at 09:31
-1

follow along on this answer's guideline thats exactly what you need to do.. open link