



















Angular内置的pipe一般用在template中,比如下面的CurrencyPipe用来格式化货币
{{a | currency:'USD':true:'1.0-0'}}
如果变量a的值是2345。格式化后会显示成$2,345。非常方便。
如果需要在component内使用原生pipe,可以用下面的方法:
import {CurrencyPipe} from '@angular/common'
.....
providers: [CurrencyPipe]import {CurrencyPipe} from '@angular/common'
....
constructor(private currencyPipe: CurrencyPipe) { ... }// $12,345
this.value = this.cp.transform(this.value, 'USD': true: '1.0-0')http://ngninja.com/posts/angular2-builtin-pipes-in-typescript
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。