0

I'm trying to see if something is possible in angular.

I want to allow for a provider in app.module.ts based on a condition from a service.

So for example:

app.module.ts

@NgModule({
  declarations, //etc
  imports: [
    BrowserModule, ' //etc
    
  providers, //this should be empty unless True is returned from a service.
  bootstrap: [AppComponent],

I have a service that will return a boolean. Based on that, I will set providers for a 3rd party tool.

Is this possible?

JoSSte
  • 2,953
  • 6
  • 34
  • 54
KingKongFrog
  • 13,946
  • 21
  • 75
  • 124
  • not sure if this is possible, but I believe you can just lazy load your services by segregating your components and services into modules which you can lazy load with router, i.e. they'll only be loaded when on that specific route – Rogelio Dec 14 '20 at 23:20
  • Yes possible... – Randy Casburn Dec 14 '20 at 23:23
  • Does this answer your question? [How to conditionally inject service into component?](https://stackoverflow.com/questions/43450259/how-to-conditionally-inject-service-into-component) – Randy Casburn Dec 14 '20 at 23:23
  • 1
    Also can use [Factory Provider](https://angular.io/guide/dependency-injection-providers#using-factory-providers) – Randy Casburn Dec 14 '20 at 23:26

0 Answers0