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 { }

 

posted on 2018-04-22 12:25  chester·chen  阅读(772)  评论(0编辑  收藏  举报