ocLazyLoad icon indicating copy to clipboard operation
ocLazyLoad copied to clipboard

Angular ocLazyLoad not load for second time

Open stefensuhat opened this issue 9 years ago • 6 comments

I'm using ocLazyLoad and initialize it at ui-router resolve:

$stateProvider
   .state('user', {
       url: '/user',
       resolve: {
       loader: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load('app/user/user.app.js');
           }]
       }
    })
   .state('admin', {
       url: '/admin',
       resolve: {
       loader: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load('app/admin.app.js');
           }]
       }
    })

The problem is when I first reload the page (to /admin), it works perfectly. But if i go to /user (still load) and back again to /admin the JS won't load. and still using /userjs.

I've tried add cache:false for every route stil not working.

Any solution?

stefensuhat avatar Dec 07 '15 08:12 stefensuhat

hmm that shouldn't be the case Try adding an error handler to see if there is something here:

$stateProvider
   .state('user', {
       url: '/user',
       resolve: {
       loader: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load('app/user/user.app.js').then(function(res) { return res; }, function(err) { console.log(err); return err;});
           }]
       }
    })
   .state('admin', {
       url: '/admin',
       resolve: {
       loader: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load('app/admin.app.js').then(function(res) { return res; }, function(err) { console.log(err); return err;});
           }]
       }
    })

If that's not the case, could you make me a plunkr with the bug so that I can find the cause ?

ocombe avatar Dec 07 '15 08:12 ocombe

When i tried console log on success, for the second time it return me undefined.

Will check my httpinterceptor. and will make the plunker.

stefensuhat avatar Dec 07 '15 08:12 stefensuhat

I am having the same issue as specified by @ssuhat. But when I load the app with Microsoft Edge and Firefox I don't get same problem. Seems the problem is happening on google chrome. Any ideas why this is?

alleypa avatar Jan 18 '16 18:01 alleypa

I am having the same issue. My route will load the first time, but if I navigate away and come back it fails. It only applies to 1 of my router states. The error I see in the console is a 404 error trying to load

http://localhost:8080/undefined

shows from ocLazyLoad.js - 128

Tested in Opera, Firefox and Chrome

I did some additional testing on this. I can verify that the values being passed into the ocLazyLoad.load function are identical in both cases that the page is being hit. However, the second time, one of the entries consistently fails to load. In my particular case it's attempting to load it through the modules/MODULE_CONFIG setup as I need to define serie:true on the particular module that I am trying to load.

jesmith17 avatar Mar 08 '16 22:03 jesmith17

listening for curiousity

dgreene1 avatar Apr 24 '17 20:04 dgreene1

是 serie:true 引起的,注掉后就可以了

a121bc avatar Mar 28 '19 07:03 a121bc