简体   繁体   中英

AngularJS - module uses config from a different file

I am new to AngularJS and I don't know if this is possible.

This is my current code:

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

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

I want to move this app.config to another file, and access from my module file. Is it possible? How can I do this?

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) {
 ... 
});

add files in your index.html with right sort:

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

Using Labjs: if you want to load files as lazyload

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM