3

We have an application where we are lazy loading modules via router. We need to load a some resources before the app module starts, but we don't want to use resolve on router. That's why we are trying to create some provider factory (APP_INITIALIZER) to load some data from server and then use it in components in that lazy loaded module. So every module will have some different settings like translations and so on...

I created a plunker for showcase. https://embed.plnkr.co/uBK23O5cA7QGwlvmbi73/ If you click on lazy it should wait 10 seconds to load the module but its not happening.

We are using angular 2.0.0 version. Thanks for any advice.


  • I think APP_INITIALIZE is used only for Application level. - yurzui
  • Possible you need to use something like this angular.io/docs/ts/latest/api/router/index/… - yurzui
  • Yes you are right, but I don't want to make this things on router. I need that every module pack his things in his level and not on level upper in router settings. - Roman Kora
  • Yes I got it now. I will use resolve on router in the submodule. There is a blank route. { path: '', component: FileSharingComponent, **resolve: ...** children: [ {path: '', redirectTo: 'cloud-service/internal-storage', pathMatch: 'full'}, {path: 'cloud-service/:cloudServiceID', component: ListOutletComponent, children: childRoutes } ] } thank you for your advices @yurzui - Roman Kora
  • I have spent a whole day looking for a solution to the same problem, and it seems that resolve suits best to solve that kind of issues :) - Burak Tasci

Linked


Related

Latest