|
|
@ -1,10 +1,24 @@ |
|
|
|
import { Component, Inject } from '@angular/core'; |
|
|
|
import { Component, Inject, OnInit } from '@angular/core'; |
|
|
|
|
|
|
|
import { OrderDetail } from './order-detail'; |
|
|
|
import { IOrderService, ORDER_SERVICE } from './order.interface'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'my-app', |
|
|
|
templateUrl: './app.component.html', |
|
|
|
styleUrls: [ './app.component.css' ] |
|
|
|
styleUrls: ['./app.component.css'], |
|
|
|
}) |
|
|
|
export class AppComponent { |
|
|
|
constructor(@Inject('LoadingPath') public loadingPath: string) {} |
|
|
|
export class AppComponent implements OnInit { |
|
|
|
total = 0; |
|
|
|
|
|
|
|
//@Inject 注入Service(ORDER_SERVICE) Token
|
|
|
|
constructor(@Inject(ORDER_SERVICE) public orderService: IOrderService) {} |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
this.orderService.details = [ |
|
|
|
new OrderDetail({ PurchaseCount: 2, UnitPrice: 200 }), |
|
|
|
new OrderDetail({ PurchaseCount: 4, UnitPrice: 50 }), |
|
|
|
]; |
|
|
|
this.total = this.orderService.computeTotal(); |
|
|
|
} |
|
|
|
} |
xxxxxxxxxx