Angularjs – 分离指令文件,但保持在同一个模块上
发布时间:2020-12-17 08:19:29 所属栏目:安全 来源:网络整理
导读:我试图将一个指令与另一个文件分开,而不必声明一个新的模块 – 不做: angular.module('myapp.newmodule',[]).directive 但只是: angular.module( ‘myapp.directives’)指令( ” myapp.directives模块存在于另一个文件中,工作正常。但是当我尝试在另一个
我试图将一个指令与另一个文件分开,而不必声明一个新的模块 – 不做:
angular.module('myapp.newmodule',[]).directive 但只是: angular.module( ‘myapp.directives’)指令( ” myapp.directives模块存在于另一个文件中,工作正常。但是当我尝试在另一个文件中使用它,如上所示(没有[])它失败。 跟随this answer它认为我的方法应该工作,但由于某种原因它失败..
当您首先声明一个模块时,需要具有依赖关系参数。之后,您可以仅使用模块名称参数引用相同的模块。
/* create module */ angular.module('myapp.newmodule',['ngRoute','ngResource']); /* declare components of same module,note same name*/ angular.module('myapp.newmodule').directive.... 如果要创建新模块,则需要将其注入主应用程序模块中作为依赖关系。 /* main ng-app module,injects another module you created below*/ angular.module('myapp.newmodule','ngResource','myUploader']); /* new module,must have dependency argument */ angular.module('myUploader',[]).directive... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |