gpt4 book ai didi

angular - 如何在 angular 2 中的 formcontrolname 上应用管道

转载 作者:行者123 更新时间:2023-12-04 14:23:37 24 4
gpt4 key购买 nike

我有一个输入类型文本,它使用 formControlName 显示值。我写了一个管道来格式化值。
如何在 formControlName 上应用此管道(测试管道)。我已阅读 here您不能直接在输入类型文本上应用管道。

@Pipe({ name: 'testPipe' })
export class TestPipe implements PipeTransform {
public transform(value: string): string {
//some logic
return value;

}
}

我怎样才能应用这个管道
<input tabindex="1" type="text" class="form-control-style" 
formControlName="abc" id="abc" name="abc"
readonly >

最佳答案

您应该能够使用双花括号表示法来使用管道。像这样:

<input tabindex="1" type="text" class="form-control-style" 
formControlName="{{'abc' | testPipe}}" id="abc" name="abc" readonly >

Demo

关于angular - 如何在 angular 2 中的 formcontrolname 上应用管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50763300/

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