import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { Product1Component } from './product1/product1.component'; import { ProductServiceService } from './shared/product-service.service'; import { Product2Component } from './product2/product2.component'; import { LoggerServiceService } from './shared/logger-service.service'; import { AnotherProductServiceService } from './shared/another-product-service.service'; @NgModule({ declarations: [ AppComponent, Product1Component, Product2Component ], imports: [ BrowserModule ], providers: [{ provide: ProductServiceService, useFactory: (logger: LoggerServiceService, config) => { if (config.dev) { return new ProductServiceService(logger); } else { return new AnotherProductServiceService(logger); } }, deps: [LoggerServiceService, 'AppConfig'] }, LoggerServiceService, { provide: 'AppConfig', useValue: { dev: false } } ], bootstrap: [AppComponent] }) export class AppModule { }