Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a directive independent from a module

The question might seem strange. But I like to organize my app in folder with directives being in a 'directives' folder, controller in a 'controllers' folder, etc....

In all the examples I've seen, directives are declared like that:

var app = angular.module('myModule').
directives('myDirective', function(){

}); 

What I want, is to declare myDirective in a separate file (which should not know about the app variable. Then when I create myModule, I'd like to assign it myDirective.

How do I do that ?

like image 684
Sam Avatar asked Dec 21 '25 10:12

Sam


1 Answers

The way I do this is to create a module of directives and then inject that into my app:

Directive

angular.module('app.directives', []).directive(...).directive(...)

App

angular.module('myApp',['app.directives'])

You can do the same for services, filters, etc...

like image 102
Thom Porter Avatar answered Dec 24 '25 01:12

Thom Porter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!