Angularjs - 分离指令文件,但保持在同一个模块上 [英] Angularjs - separating directive files, but staying on the same module

查看:22
本文介绍了Angularjs - 分离指令文件,但保持在同一个模块上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将指令分离到另一个文件,而不必声明新模块 - 不这样做:

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').directive(''

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.

遵循这个答案它相信我的方法应该有效,但由于某种原因它失败了..

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

推荐答案

当你第一次声明一个模块时,它需要有依赖参数.之后,您可以仅使用模块名称参数来引用同一个模块.

When you first declare a module it needs to have the dependency argument. Afterwards you can reference 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-app 模块中.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆