angularAMD icon indicating copy to clipboard operation
angularAMD copied to clipboard

app.js: move app.config() into a config.js file.

Open dave-k opened this issue 9 years ago • 4 comments

I have an AngularAMD application as described here http://marcoslin.github.io/angularAMD/#/home

Can the app.config( ) { ... } section of code be moved from app.js into a config.js file? Where is the new config.js file loaded?

app.js

define(['angularAMD', 'angular-route'], function (angularAMD) {
    var app = angular.module("webapp", ['ngRoute']);
    app.config(function ($routeProvider) {
        $routeProvider.when("/home", angularAMD.route({
            templateUrl: 'views/home.html', controller: 'HomeCtrl',
            controllerUrl: 'ctrl/home'
        }))
    });
    return angularAMD.bootstrap(app);
});

dave-k avatar Sep 04 '15 20:09 dave-k

+1, have several large config files and would love the ability to load config outside of the app file.

F1LT3R avatar Nov 24 '15 20:11 F1LT3R

Seems like this project is discontinued... Any thoughts about this issue @marcoslin ?

ivosantiago avatar Mar 22 '16 14:03 ivosantiago

It seems like a lot at first to try doing what this plugin is doing, but it's not too bad if you take small steps and commit to the process.

I got frustrated with it because there always seemed to be JavaScript load errors when I tried using this library. I could never work out if it was me just doing it wrong (probably) or if it was something in the library that was not quite right.

So I ended up starting from with require-js and angular ui-router scratch with these ideas and came up with something usable, maybe it will help:

Basic demo: http://plnkr.co/edit/XU7MIXGAnU3kd6CITWE7?p=info More complete template: https://github.com/F1LT3R/angular-require-lazyload-template

Dan Wahlin's post is pretty helpful: http://weblogs.asp.net/dwahlin/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs

F1LT3R avatar Mar 22 '16 15:03 F1LT3R

Sorry guys... The day job is killing me and leaving me no time to address my side projects. The quick answer to the question is that yes, you can move the config to a config.js file but the current implementation will only allow this to be done after bootstrap.

Take a look at the example here: https://plnkr.co/edit/G4pII6?p=preview

Basically, app.js defines the home state and page2 state is defined in config.js which is only called when home_ctrl is loaded.

marcoslin avatar Mar 22 '16 17:03 marcoslin