ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Module's config loaded via ocLazyLoad is not getting called #426

Open venugopal-annamaneni opened 6 years ago

venugopal-annamaneni commented 6 years ago

Lazyload Config in Parent App

{
    name: "lazyload-module",
    files: ["http://link_to_lazyload_module_js"],
    reconfig: true,
    rerun: true
},

Module Code to be LazyLoaded


(function() {
    var __MODULE_NAME = "lazyload-module";

    var app = function(angular) {
        "use strict";

        angular.module(__MODULE_NAME, ["oc.lazyload"]).config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) {
            $ocLazyLoadProvider.config({
                debug: true,
                events: true,
                modules: [{
                       name : 'module1_in_lazyload_module',
                       files : ["resource_link_11","resource_link_12"]
                },{
                       name : 'module2_in_lazyload_module',
                       files : ["resource_link_21","resource_link_22"]
                }]
            });
        }]);

        angular.module(__MODULE_NAME, __DEPS["module_deps"]).run(function($ocLazyLoad){

            $ocLazyLoad.load(["module1_in_lazyload_module","module2_in_lazyload_module"]).then(function (data) {

            });
        });

        return angular.module(__MODULE_NAME);
    };

    if ((typeof window !== "undefined" && window !== null ? window.angular : void 0) != null) {
        app(window.angular);
    } else if (typeof require === "function") {
        var angular = require("angular");
        app(angular);
    } else {
        throw new Error("Could not find angular on window nor via require()");
    }

    if (typeof module !== "undefined" && module !== null) {
        module.exports = __MODULE_NAME;
    }
}).call(this);

Issue the config and run in the lazyload-module is not getting called when the module itself is loaded via lazyload from parent app.

What is the issue/mistake here ? Basically what am trying to do is recursively lazyload modules on demand and not everything in the parent app.

Config and run of lazyload-module is called when this is directly loaded in Parent App

venugopal-annamaneni commented 6 years ago

If someone is looking at this issue and want a working demo, please let me know. I can setup plunker with my case.

ramarivera commented 5 years ago

Hey @venugopal-annamaneni, did you get it to work?