来描述我的障碍,一个小故事。我注入了所有的需求路径文件(基本上是指令),这些文件包含对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 )中定义相同的内容时,它不起作用。然而,我感到惊讶的是,在这种情况下,工厂函数可以工作,而不是指令。
任何帮助都将不胜感激。谢谢
发布于 2015-04-30 14:25:31
你试过使用应用程序来创建指令吗?
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之前加载指令。有关更多细节,请参见加载应用程序宽模块。
https://stackoverflow.com/questions/29940181
复制相似问题