为了形容我的障碍,我会讲一些小故事。我正在注入所有requirejs路径文件(基本上是伪指令),其中包含对app.js中我的主模块的任何指令,效果很好。它有点像
define(['angularAMD', 'angular-route', 'angular-resource', 'angularTranslate', 'angularTranslateLoaderStaticFiles', 'bootstrap', 'angular-idle', 'loadingMaskDirective', 'multiselectDirective', 'treeview.directive', 'tabs', 'checklist.directive'], function(angularAMD) {
var app = angular.module("myApp", ["ngRoute", "ngResource", "ngTable", "myApp.directives", 'ui.bootstrap', 'flow']);
app.config(....){
/**some route provider**/
}...
angularAMD.bootstrap(app);
return app;
我已经定义了所有指令,并将它们注入到主模块中。但是我想在其indivisual控制器中定义一些指令以减少初始负载。必须有一些方法。对 !!
我的指令js文件中的代码看起来像..
define(['angular'], function() {
angular.module('myApp').directive('SomeDirective',
['$parse', '$compile', '$rootScope', '$filter', function($parse, $compile, $rootScope, $filter) {
.........
因此,当我尝试在app.js中而不是在页面控制器中定义相同内容时,它不起作用。但是,令我惊讶的是,这种情况下的工厂功能有效,但不适用于指令。
任何帮助将不胜感激。谢谢
您是否尝试过使用app来创建指令?
define(['app'], function(app) {
app.directive('SomeDirective',
['$parse', '$compile', '$rootScope', '$filter', function($parse, $compile, $rootScope, $filter) {
.........
提供的替代方法angularAMD
是:
define(['angularAMD'], function(angularAMD) {
angularAMD.directive('SomeDirective',
['$parse', '$compile', '$rootScope', '$filter', function($parse, $compile, $rootScope, $filter) {
.........
第二种方法的好处是允许您在加载指令之前先加载指令app.js
。有关更多详细信息,请参见加载应用程序范围模块。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句