1

I have an angular module loaded lazy using the new angular 8 method:

loadChildren: () => import('path').then(module => module.MyModuleClass)

This works fine, but now I require to configure the module. Normally this is easily achieved by implementing a static forRoot() method that returns a ModuleWithProviders object. But if I call it like this:

loadChildren: () => import('path').then(module => module.MyModuleClass.forRoot(myConfig))

... then I get a runtime error Error: Uncaught (in promise): Error: No NgModule metadata found for '[object Object]'.

Is there a way to use a module configuration for lazy loaded modules?

4
  • a service might be an alternative for you to pass attributes to the lazy loaded class Commented Oct 24, 2019 at 12:27
  • Sadly it is a requirement for the lazy module to work independent of the main application, because it should be possible to load it into different applications. Commented Oct 24, 2019 at 16:12
  • you can always have a central configurations service that both your main app and this other module share, but I will keep a tab on this question. Someone else might give us an alternative Commented Oct 25, 2019 at 23:44
  • 1
    this was someone else's answer for this question: stackoverflow.com/a/48602054/4604645 so it seems we cannot use forRoot on lazy loading Commented Oct 26, 2019 at 0:08

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.