我的main.js
位于应用程序的根文件夹中。
-app
|_ routes.js
|_ main.js
-components
|_directives
|_abc-directive.js
如何定义可以从另一个文件夹添加的指令。
我试过这个:
abc-directive.js
:
var abcDirective = function() {
// directive code
}
main.js
:
app.main = angular.module('main', ['ngRoute', 'components.directives']);
app.main.directive('abcDirective', "<I don't want to define a directive here,
rather load from diff. folder>");
最佳答案
您可以在自己的模块中定义 Controller 、指令,并将这些模块添加为主模块的依赖项
abc-directive.js
var app = angular.module('directives.abcDirective', [])
app.directive('abcDirective', ...
main.js
var app = angular.module('mainApp', ['directives.abcDirective'])
您可以使用RequireJS管理依赖关系..
关于javascript - 如何在应用程序中注入(inject)/加载 Angular 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25361029/