0

描述我的障碍,一个小背景故事。我正在注入所有 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;

我已经定义了所有指令并将它们注入主模块。但我想在他们的独立控制器中定义一些指令以减少初始负载。必须有某种方法。正确的 !!

我的指令 js 文件中的代码看起来像..

define(['angular'], function() {
angular.module('myApp').directive('SomeDirective',
        ['$parse', '$compile', '$rootScope', '$filter', function($parse, $compile, $rootScope, $filter) {
.........

所以,当我尝试在页面控制器而不是 app.js 中定义相同的内容时,它不起作用。但是,我很惊讶在这种情况下工厂功能有效但指令无效

任何帮助将不胜感激。谢谢

4

1 回答 1

2

您是否尝试过使用 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. 有关更多详细信息,请参阅加载应用程序范围模块

于 2015-04-30T14:25:31.777 回答