Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The module config is not triggered #5

Closed
ocombe opened this issue Mar 12, 2014 · 23 comments
Closed

The module config is not triggered #5

ocombe opened this issue Mar 12, 2014 · 23 comments
Labels

Comments

@ocombe
Copy link
Owner

ocombe commented Mar 12, 2014

It seems that the config part of a module lazy loaded is not triggered:

angular.module('order', []).config(['$stateProvider', function($stateProvider) {
   console.log('in order.config');
   console.log('$stateProvider');
   console.log($stateProvider);
}]);

I should check out if this is actually the case, and if so fix it

@ocombe
Copy link
Owner Author

ocombe commented Mar 31, 2014

It is in fact triggered, nevermind :)

@ocombe ocombe closed this as completed Mar 31, 2014
@edgar0011
Copy link

actually it is triggered only with reconfig:true. Should the config be triggered for the first time module has been loaded, regardless of reconfig parameter?

@ocombe
Copy link
Owner Author

ocombe commented Aug 25, 2014

yes it should, do you have an example where it is not the case ?

@edgar0011
Copy link

http://ngproject.herokuapp.com/#/notes
notesModules.js
if debug, you will see only .run is triggered

app.js is main app module

@ocombe
Copy link
Owner Author

ocombe commented Aug 25, 2014

Hmm you're right, there is something fishy here, I'll check it out tomorrow, thanks

@ocombe ocombe reopened this Aug 25, 2014
@ocombe ocombe added the bug label Aug 26, 2014
@ocombe ocombe closed this as completed in 300882a Aug 26, 2014
@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

Ok thanks for the report, there was a stupid coding mistake in my code (I really need to finish those unit tests), it's fixed now, I should publish a new version soon.

@edgar0011
Copy link

Thanks, great, the lib is fantastic, together with uiRouter makes perfect couple :-)

@edgar0011
Copy link

Hi, i think it is not working, problem could be here:

for(i = 0, len = queue.length; i < len; i++) {
            args = queue[i];
            if(angular.isArray(args)) {
                if(providers.hasOwnProperty(args[0])) {
                    provider = providers[args[0]];
                } else {
                    throw new Error('unsupported provider ' + args[0]);
                }
                var invoked = regConfigs.indexOf(moduleName);
                if(registerInvokeList(args[2][0]) && (args[1] !== 'invoke' || (args[1] === 'invoke' && invoked === -1)) || (args[1] === 'invoke' && reconfig)) {
                    if(invoked === -1) {
                        regConfigs.push(moduleName);
                    }
                    provider[args[1]].apply(provider, args[2]);
                }
            }
        }
regConfigs.push(moduleName);

it can be called more times with the same moduleName, moduel,controller, .directive functions,
module,config()

i think you should save in the regConfigs array more specific token, like module name + function.toString that invoked the call?

try load module that calls .controller and .config methods

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

If you want to call it more than one time, you need to use the parameter reconfig:true. There are many times where you don't want the config function to be called multiple times, that's why it has to be voluntary.
This part of the code is to know if the module config block has been invoked. Only modules have a config block that's why the module name is a sufficient distinction.

@edgar0011
Copy link

sure, but in many times you declare some service/provider as module.provider() and then configure it in .config() method, and still need to call these for the first time...

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

That's why there is the parameter reconfig :)

@edgar0011
Copy link

sou you cannot call these on lazy loaded module?

angular.module("notesModule", [
    "ui.router",
    {
        name: 'notesModule',
        files: [
            'modules/css/styles.css'
        ]
    }
])
    .controller("NotesController", ["$scope", NotesController])

    .config(function($provide){

        alert("notesModule config ");

        //$provide.controller("NotesController", ["$scope", NotesController]);
    })

only .controller is called

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

It should be:

angular.module("notesModule", [
    "ui.router",
    {
        files: [
            'modules/css/styles.css'
        ]
    }
])
    .controller("NotesController", ["$scope", NotesController])

    .config(function($provide){

        alert("notesModule config ");

        //$provide.controller("NotesController", ["$scope", NotesController]);
    })

You don't need to specify the name property when you load non-angular files, and if you're calling the module as a dependency of itself it is an endless recursive behavior.
But if you remove this, it should work and the config should be invoked once (with the version 0.3.4 of the lib). Isn't it ?

@edgar0011
Copy link

no, still called only once, yes 0.3.4

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

Yes, that's how it is supposed to be.

the config should be invoked once (with the version 0.3.4 of the lib)

Use reconfig:true if you want to call it each time you lazy load it.

@edgar0011
Copy link

I dont thing you understand what I mean, .config is not called even for the first time, if you call .controller before, (and assume same it is with service, constant, value....)

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

And if your code was:

angular.module("notesModule", [
    "ui.router",
    {
        files: [
            'modules/css/styles.css'
        ]
    }
])
    .config(function($provide){

        alert("notesModule config ");

        //$provide.controller("NotesController", ["$scope", NotesController]);
    })

    .controller("NotesController", ["$scope", NotesController])

It would work ? Because the config is before the controller ?

@edgar0011
Copy link

yes then it works

@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

Ok ! Then yes I did not understand the problem, thanks !
I'll see how to fix that :)

@ocombe ocombe reopened this Aug 26, 2014
@edgar0011
Copy link

anf if I add:

.controller("NotesController", ["$scope", NotesController])

    .factory("NotesService", function($q){

        alert("NotesService");
        return {
            name:"NotesService"
        }
    })

after .config, these are not called, invokeQueue has been called with .config......

@ocombe ocombe closed this as completed in 1e29c9d Aug 26, 2014
@ocombe
Copy link
Owner Author

ocombe commented Aug 26, 2014

Ok I fixed a bunch of bugs and released 0.3.5, thanks for your persistence because I found multiple cases where config would not be called !

The config block would not be called if:

  • defined multiple times (only the first 1 would be invoked)
  • defined with an auto injected module: ['...', function() {}]
  • defined after another component: angular.module().controler().config()

@edgar0011
Copy link

great, gonna test now

@edgar0011
Copy link

Works great, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants