AngularJS - 模块使用来自不同文件的配置

AngularJS - module uses config from a different file

我是 AngularJS 的新手,我不知道这是否可行。

这是我当前的代码:

var app = angular.module('qlikCockpitApp',['pascalprecht.translate','720kb.tooltips']);

app.config(['$translateProvider', function ($translateProvider) {
... 
});

我想将此 app.config 移动到另一个文件,并从我的模块文件访问。可能吗?我怎样才能做到这一点?

You can add 2 file or more for each part of your application

Remember in this case you have 1 app this mean (var app = angular.module('qlikCockpitApp', []))

app.js

var app = angular.module('qlikCockpitApp',['pascalprecht.translate','720kb.tooltips']);

app.config.js

app.config(['$translateProvider', function ($translateProvider) {
 ... 
});

index.html 中添加文件并正确排序:

<script src="app.js"></script>
<script src="app.config.js"></script>

使用 Labjs: 如果你想以延迟加载方式加载文件

index.html

<div id="app"></div>
<!--required: download labjs library-->
<script src="lab-library.js"></script>
<script src="bootstrapper.js"></script>

in this case do not use ng-app set id attribute

bootstrapper.js

$LAB.script(
    "/angular.js",
    "/app.js",
    "/app.config.js"
)
.wait(function () {
    var root = document.getElementById("app");
    angular.bootstrap(root, ["app"]);
});

Add / before files directory