marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

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

Open dave-k opened 9 years ago

dave-k commented 9 years ago

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);
});
F1LT3R commented 8 years ago

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

ivosantiago commented 8 years ago

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

F1LT3R commented 8 years ago

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

marcoslin commented 8 years ago

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.