AngularJS两个指令具有相同的模块名称 [英] AngularJS Two directives with the same module name
问题描述
是否有可能创建两个指令具有相同的模块名称?
有了这两个文件
Is it possible to create two directives with the same module name? Having this two files
angular.module('fabTemplate', [])
.directive('fabGallery', [function () {
....
和
angular.module('fabTemplate', [])
.directive('fabVideo', [function () {
...
第二个指令将无法识别。
The second directive will not be recognised.
<fab-video />
不呈现任何内容。通过改变模块名工作虽然。
does not render anything. By changing the module name works though.
AngularJS的文件说的参数名称(模块的第一个参数办法)
AngularJS's documentation says that the parameter name (first param of module "method")
模块的名称创建或检索
我想应该工作,然后...:•
角不打印任何东西到控制台
I suppose that should work then... :S Angular doesn't print anything into the console
推荐答案
如果你想获取一个模块,那么你只能使用angular.module的第一个参数()。
If you want to retrieve a module, then you must use only the first param of angular.module().
从文档:
要求(可选)[阵列]:如果指定然后正在创建新的模块。如果未指定则模块检索进行进一步的配置。
requires (optional) [Array.] : If specified then new module is being created. If unspecified then the the module is being retrieved for further configuration.
您code应该是这样的:
Your code should be something like:
//Module definition:
angular.module('fabTemplate', []);
//Get the module and add the first directive:
angular.module('fabTemplate').directive('fabGallery', function () {});
//Get the module and add the second directive:
angular.module('fabTemplate').directive('fabVideo', function () {});
这篇关于AngularJS两个指令具有相同的模块名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!