Browse Source

useValue抽象服務

可將物件實體抽換掉服務類別,可以透過建立間諜SPY物件模擬測試情境
master
HarveyMac 2 years ago
parent
commit
0947394269
  1. 5
      src/app/app.module.ts

5
src/app/app.module.ts

@ -9,7 +9,10 @@ import { OrderDiscountService } from './order-discount.service';
@NgModule({ @NgModule({
imports: [BrowserModule, FormsModule], imports: [BrowserModule, FormsModule],
declarations: [AppComponent], declarations: [AppComponent],
providers: [{ provide: OrderService, useExisting: OrderDiscountService },OrderDiscountService],
providers: [{
provide: OrderService,
useValue:{computeTotal:()=>100},
},],
bootstrap: [AppComponent], bootstrap: [AppComponent],
}) })

Loading…
Cancel
Save