gpt4 book ai didi

angular - 在 angular2 的自定义管道上扩展管道,如货币或数字

转载 作者:太空狗 更新时间:2023-10-29 17:09:40 26 4
gpt4 key购买 nike

我想在我的自定义管道上调用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com