marcoslin / angularAMD

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

The app.config() is not being loaded #143

Closed WellMafra closed 9 years ago

WellMafra commented 9 years ago

I'm having a problem, my app.config is not being called or loaded... I think that the var "app" is not ready, I saw the Issue https://github.com/marcoslin/angularAMD/issues/123, but my configurations about RequireJs is different, follow some parts of my code:

Main.js

require.config({
    baseUrl: 'scripts/',
    paths: {
        'angular': '/bower_components/angular/angular',
        'angularAMD': '/bower_components/angularAMD/angularAMD.min',
        ...
    },
    shim: {
        'angularAMD': [ 'angular' ],
        ...
    },
    deps: ['app']
});

App.js

define(['common'], function (angularAMD) {
    'use strict';
    var app = angular.module('zuptApp', [........]);
    ...
    return angularAMD.bootstrap(app);
});

Config.js

define(['app'], function (app) {
    'use strict';

    app.config(function () {
        ...
    });
});
marcoslin commented 9 years ago

Looks like Config.js is a separate file for you. Where is it being loaded? You should really put the config in the app.js file until #123 is implemented.

WellMafra commented 9 years ago

My file Config.js is a dependency of the HomeController, this controller is the first controller called in my app. But, if I can not have app.config in separate file, there is no matter. May I have my config in a separate file?

marcoslin commented 9 years ago

Sorry but I am having a hard time understanding why you need to have app.config in a different file. Can you let me know what are you using this for and maybe I can think of an alternative?

WellMafra commented 9 years ago

In my case... Just to have each file with each responsibility. But, there is no problem, I'll put my config in app.js More one thing... Just for curiosity: What's the restriction? Can I help you to fix it?

Tks for your time.

marcoslin commented 9 years ago

The restriction is really educating the user base that config must be ran before the bootstrap or often it is not going to work. If you are dealing with package that can be configure after bootstrap, you can try to call angularAMD.config.

WellMafra commented 9 years ago

Yesterday, I had a situation. I putted the config in my app.js, but I'm using mocks for fakes data. To config the mock, I have a file, with to many configurations, and the file is big. To fix the problem, I created a new file to start my application: appMock.js, just for separate the things, and this file is called in main.js :

require.config({
    ...
    ...
    //start app
    deps: ['appMock']
});

I didn't like to do that, and its calling app.js yet. Its not calling the appMock.js I don't know why.

I'll test the angularAMD.config . Instead I receive the app parameter, I'll receive the AngularAMD? Ex:

Currently Config.js

define(['app'], function(app) {
    ...
});

Changed Config.js

define(['angularAMD'], function(AngularAMD) {
    ...
});

Would be this?