0

I have situation where a resolver should start resolving only once a configuration API response is received.

Initially, a configuration API is called from app.component.ts. This response is saved in localstorage. The resolver needs to get the attributes from config data stored in localstorage to pass to API called from Resolver.

  1. If the localstorage is already present in the application, the resolver works fine.
  2. But if we try to hit the URL directly, the resolver will not receive the localstorage data as the configuration API response might be delayed or not saved to localstorage when resolver tries to access them.

UPDATE: All API calls are using subscribe function

How can I able to execute resolver only once the configuration API response is received and saved to localstorage.

Thanks in advance

sadiqmc
  • 171
  • 2
  • 15
  • 1
    Any code which you have tried so far to achieve this? – Pardeep Jain May 03 '18 at 04:52
  • @PardeepJain The config API is called using subscribe function. When I tried with console.log(), the resolver is called before receiving response from config API. – sadiqmc May 03 '18 at 05:16
  • @PardeepJain I can't help with sharing code but if you need any specific section like config API call, routing module, i would able to share the snippets – sadiqmc May 03 '18 at 05:38
  • @PardeepJain here is a sample snippet https://stackblitz.com/edit/angular-7j8lwg – sadiqmc May 03 '18 at 05:50

1 Answers1

0

Resolved using APP_INITIALIZER token

Example code here

sadiqmc
  • 171
  • 2
  • 15