Skip to content

Instantly share code, notes, and snippets.

@fireflysemantics
Last active September 8, 2022 01:38
Show Gist options
  • Save fireflysemantics/2fe61964fb53ae173d9dcd7f5937ee76 to your computer and use it in GitHub Desktop.
Save fireflysemantics/2fe61964fb53ae173d9dcd7f5937ee76 to your computer and use it in GitHub Desktop.
import { ModuleWithProviders, NgModule } from '@angular/core';
import { GreetingService } from './greeting.service';
import { GreetingServiceConfig } from './greeting-service.config';
import { GREETING_SERVICE_CONFIG_INJECTION_TOKEN } from './greeting-service.token';
@NgModule({
providers: [GreetingService],
})
export class GreetingServiceModule {
constructor(greetingService: GreetingService) {
greetingService.initialize();
}
static config(
config?: Partial<GreetingServiceConfig>
): ModuleWithProviders<GreetingServiceModule> {
return {
ngModule: GreetingServiceModule,
providers: [
{
provide: GREETING_SERVICE_CONFIG_INJECTION_TOKEN,
useValue: Object.assign(new GreetingServiceConfig(), config),
},
],
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment