我想在我的自定义管道上调用 numberPipe 我找到了这个答案
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
}
}
最佳答案
可能过时了,但这对我有用(Angular 5):
import { Pipe, PipeTransform } from '@angular/core';
import { DecimalPipe } from '@angular/common'
@Pipe({
name: 'bigInteger'
})
export class BigInteger extends DecimalPipe implements PipeTransform {
transform(value: any, args?: any): any {
let result;
result = super.transform(value, args);
//any transformations you need
return result;
}
}
然后你就可以像普通的number管道一样使用它,但是可以根据你的意愿进行定制:
<span>{{someValue | bigInteger : '1.2-2'}}</span>
关于angular - 在 angular2 的自定义管道上扩展管道,如货币或数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38971085/