alonisser alonisser - 1 month ago 8
AngularJS Question

Angularjs - separating directive files, but staying on the same module

I'm trying to separate a directive to another file, without having to declare a new module - not doing:

angular.module('myapp.newmodule',[]).directive


but just :

angular.module('myapp.directives').directive(''

the myapp.directives module exists in another file and works fine. but when I try to use it in another file as shown above (without
[]
) it fails.

following this answer It believe my approach should work, but for some reason it fails..

Answer

WHen you first declare a module it needs to have the dependency argument. Afterwards you can refrence that same module using only the module name argument.

/* create module */
angular.module('myapp.newmodule',['ngRoute','ngResource']);

/* declare components of same module, note same name*/
angular.module('myapp.newmodule').directive....

If you want to create new modules, you need to inject them in the main ng-app module as dependencies

/* main ng-app module , injects another module you created below*/
angular.module('myapp.newmodule',['ngRoute','ngResource','myUploader']);


/* new module, must have dependency argument */
angular.module('myUploader',[]).directive....