ocombe / ocLazyLoad

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

Angular Config block is never getting called #393

Open AmsaveniMidhun opened 7 years ago

AmsaveniMidhun commented 7 years ago

In the below code snippet, my js file is getting invoked, but the config part is not being called in app.state.js. Please help me in this,

app.module.js :

(function() { 'use strict';

 var app= angular
    .module('IloadsApp', [
        'ngStorage',
        'tmh.dynamicLocale',
        'pascalprecht.translate',
        'ngResource',
        'ngCookies',
        'ngAria',
        'ngCacheBuster',
        'ngFileUpload',
        'ui.bootstrap',
        'ui.bootstrap.datetimepicker',
        'ui.router',
        'infinite-scroll',
        // jhipster-needle-angularjs-add-module JHipster will add new module here
        'angular-loading-bar'
    ]);
   app.run(run);

run.$inject = ['stateHandler', 'translationHandler'];

function run(stateHandler, translationHandler) {
    stateHandler.initialize();
    translationHandler.initialize();
}

})();

app.state.js :

(function() {

'use strict'; 

angular .module('IloadsApp') .config(stateConfig);

stateConfig.$inject = ['$statePsrovider'];

alert ("before Inside ");

**function stateConfig($stateProvider) {
    alert ("Inside ");
    $stateProvider.state('app', {
        abstract: true,

        views: {
            'navbar@': {
                templateUrl: 'app/navbar/navbar.html',
                controller: 'NavbarController',
                controllerAs: 'vm'
            }
        },
        resolve: {
            authorize: ['Auth',
                function (Auth) {
                    return Auth.authorize();
                }
            ],
            translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                $translatePartialLoader.addPart('global');
            }]
        }
    });
}**
alert("After");

})();

AmsaveniMidhun commented 7 years ago

@gmarziou any updates here ?

jeevasusej commented 7 years ago

From your code

angular
.module('IloadsApp')

I understood that you are not creating the module. You are referring the existing module. The configuration part will be called only once at module creation. Not when module has been got by you. Check like below, the configuration part will be called.

angular
.module('IloadsApp',[])
.config(stateConfig);