4
自定义管道延长像货币或数字管道,我想呼吁我的自定义管道numberPipe我觉得这个答案上angular2
Angular2 use basic pipe in custom pipe
,但我这个解决方案没有为我工作。我有一个错误 “管道 'BIGINTEGER' 无法找到”
import { Pipe, PipeTransform } from "@angular/core"
import { CurrencyPipe } from "@angular/common"
@Pipe({
name: "bigInteger"
})
export class BigInteger extends CurrencyPipe implements PipeTransform {
transform(value: any): string {
return value
}
}
除了这个,我也参加了视图模板使用我的自定义管道时得到一个错误,抱怨,有没有CurrencyPipe的提供者。所以为了解决这个错误,在我的app.module.ts中,我将它添加到Providers列表中:'providers:[...,CurrencyPipe]'现在我的基于它的自定义管道起作用了!现在,我确信这可能不是最佳实践,但我需要看到一些合理的方法来覆盖默认管道,或者有更好的方法吗? – FireDragon
此外,CurrencyPipe可以在'@ angular/common'中的Angular的公共模块'import {CurrencyPipe}中找到;'' – FireDragon