ocLazyLoad
ocLazyLoad copied to clipboard
Angular ocLazyLoad not load for second time
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 /user
js.
I've tried add cache:false
for every route stil not working.
Any solution?
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 ?
When i tried console log on success, for the second time it return me undefined.
Will check my httpinterceptor. and will make the plunker.
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?
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.
listening for curiousity
是 serie:true 引起的,注掉后就可以了