0

Consider the following snippet. How do I access the provided value of Environment in forRoot? Is there an alternate way that I do the same?


interface Environment {
  tokens: Record<string, string>;
}

const ENVIRONMENT = new InjectionToken<Environment>('ENVIRONMENT');

// `SomeModule` with `forRoot` to configure it. This module is from an external library.

// Some library module that I'm creating
@NgModule({
  imports: SomeModule.forRoot() // `tokens` needs to passed here.
})
export class MyLibraryModule {}

MyLibraryModule will be consumed in some application where ENVIRONMENT will be injected. It will be lazily loaded

Anurag Kumar
  • 95
  • 1
  • 2
  • 8
  • Does this answer your question? [Passing environment variables to angular library](https://stackoverflow.com/questions/43529920/passing-environment-variables-to-angular-library) – Zakaria Acharki Apr 17 '21 at 11:06
  • No. I have updated the question. Two differences: `MyLibraryModule` will be lazily loaded. And, I will not have access to actual environment, only the injected token. – Anurag Kumar Apr 17 '21 at 12:12

0 Answers0