Angularjs - 分离指令文件,但住在同一模块上 [英] 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
但就是:
angular.module('myapp.directives')。指令(''
angular.module('myapp.directives').directive(''
在myapp.directives模块存在于另一个文件和工作正常。但是当我尝试在另一个文件中使用它,如上所示(不含 []
)失败。
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.
以下<一个href=\"http://stackoverflow.com/questions/16771812/angularjs-seed-putting-javascript-into-separate-files-app-js-controllers-js\">this回答它认为我的方法应该可行,但由于某种原因失败了。
following this answer It believe my approach should work, but for some reason it fails..
推荐答案
当你第一次声明,它需要有依赖参数的模块。之后,您可以只使用该模块名称参数refrence相同的模块。
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....
如果您要创建新的模块,你需要的主 NG-应用
模块依赖关系注入其中
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....
这篇关于Angularjs - 分离指令文件,但住在同一模块上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!