0
我有一個服務,我在app.run()
期間調用,由於某種原因,當我加載文件異步時,他們似乎沒有采取。在運行時加載角度指令
下面是我使用的服務:
angular.module('nav').service('SubmoduleService', ['submodules_config',
function(config){
this.autoload = function(){
for(var key in config.modules){
for(var i=0; i<config.modules[key].length; i++){
var src = config.modules[key][i].replace(':path', config.path).replace(':name', key);
console.log(src);
var js = document.createElement("script");
js.type = "text/javascript";
js.src = src;
document.body.appendChild(js);
}
}
return true;
};
}]);
這裏的配置文件:
angular.module('nav').constant('submodules_config', {
path: "scripts/submodules/:name",
modules: {
gallery: [':path/config.js', ':path/directive.js']
}
});
所以基本上配置定義模塊和所有需要得到加載該模塊的文件。
我看到文件被加載到DOM中,但由於某種原因,當我加載使用該指令的控制器時,它不起作用。
注意:該指令在顯式加載文件時起作用。
任何幫助表示讚賞。
E
我很熟悉要求。我只是不喜歡在我的所有文件中使用閉包系統。我只是尋找一種簡單的方法來選擇在引導時加載模塊。 – 2015-03-04 17:11:20