angular-docs-cn/public/docs/_examples/architecture/ts/app/sales-tax.service.ts

15 lines
381 B
TypeScript

import { Injectable } from '@angular/core';
import { TaxRateService } from './tax-rate.service';
@Injectable()
export class SalesTaxService {
constructor(private rateService: TaxRateService) { }
getVAT(value: string | number) {
let amount = (typeof value === 'string') ?
parseFloat(value) : value;
return (amount || 0) * this.rateService.getRate('VAT');
}
}