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.

7
  • I think APP_INITIALIZE is used only for Application level. Commented Nov 10, 2016 at 8:36
  • 1
    Possible you need to use something like this angular.io/docs/ts/latest/api/router/index/… Commented Nov 10, 2016 at 9:21
  • 1
    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. Commented Nov 10, 2016 at 9:28
  • 1
    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 Commented Nov 10, 2016 at 9:34
  • 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 :) Commented Jan 27, 2017 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.