Giter Club home page Giter Club logo

Comments (23)

ocombe avatar ocombe commented on May 12, 2024

It is in fact triggered, nevermind :)

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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?

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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

app.js is main app module

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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.

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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.

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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...

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

That's why there is the parameter reconfig :)

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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 ?

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

no, still called only once, yes 0.3.4

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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.

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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....)

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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 ?

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

yes then it works

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

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......

from oclazyload.

ocombe avatar ocombe commented on May 12, 2024

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()

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

great, gonna test now

from oclazyload.

edgar0011 avatar edgar0011 commented on May 12, 2024

Works great, thanks a lot.

from oclazyload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.