0

I need to use the environment.production flag in an import array of a NgModule:

@NgModule({
  import: [
    ...
    !environment.production ? StoreDevtoolsModule.instrument() : [],
  ]
}

But we've multiple possible environment files at this time, that's why we use an InjectionToken in other parts of the code.

Is there a possibility to use the injection token in the import array?

Marc Rambow
  • 86
  • 1
  • 8
  • 2
    I believe you would need to use the `forRoot` pattern, which allows you to pass parameters to the module when importing it in the app. Does that sound like it makes sense? – Will Alexander Jan 05 '23 at 08:40
  • Yes, it does, but I was hoping for an easier solution :D – Marc Rambow Jan 05 '23 at 08:42
  • Haha I understand, but it's not very complicated ^^ would you like me to post an example? – Will Alexander Jan 05 '23 at 08:43
  • No need, already done it in other modules. Thanks! :) – Marc Rambow Jan 05 '23 at 08:52
  • @WillAlexander I changed my mind, I need an example :D With `forRoot` I can change the providers, but not the imports , at least I don't know how.. – Marc Rambow Jan 12 '23 at 10:22
  • Rereading this, I can see the issue. There are a few different options. Can you tell me more about your specific use case? Do you import different versions of modules depending on the environment? – Will Alexander Jan 17 '23 at 08:11

0 Answers0