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