Pass environment data using forRoot

53 Views Asked by At

I'm trying to pass environment data using forRoot, here is code example:

Parent app:

   @NgModule({
      declarations: [AppComponent],
      imports: [
        ...
        SimpleModule.forRoot(environment), // pass environment to Child app
      ],
      providers: [],
      bootstrap: [AppComponent],
    })
    export class AppModule {}

Child app:

@NgModule({
  imports: [
    ...
    someApiModule.forRoot(environment.apiConfig), // inject environment here
  ],
  exports: [...],
  declarations: [...]
})
    export class SimpleModule{
          static forRoot(environment: any): ModuleWithProviders<SampleModule> {
            console.log(environment); // environment from parent app
            return {
              ngModule: SampleModule,
              providers: [SampleService, {provide: 'environment', useValue: environment}]
            };
          }
        }

What is the current way to inject the environment to someApiModule?

  • I've try this approach and it won't help.
  • and @Inject decorator from the constructor and than inject the environment emphasized textup to: someApiModule, also won't help.

I tried to save locally the environment in a temp variable but I have no way to move it up into the scope of imports inside @NgModule.

Thanks for the helpers.

0

There are 0 best solutions below