Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在值更改时更新被动表单中的字段_Angular_Angular Reactive Forms - Fatal编程技术网

Angular 在值更改时更新被动表单中的字段

Angular 在值更改时更新被动表单中的字段,angular,angular-reactive-forms,Angular,Angular Reactive Forms,我想直接将输入的内容格式化为被动形式(最好在显示之前)。 按照我目前的方法,我尝试使用“valueChanges”订阅字段 但这会导致递归,这是可以理解的。每次我更改subscribe字段中的值时,都会再次调用它 因此,我的问题是,如何在显示之前直接编辑输入 导出类NewPaymentComponent实现OnInit{ 付款方式:FormGroup; 构造函数(){} ngOnInit():void{ this.paymentForm=新表单组({ amountFormatted:new Fo

我想直接将输入的内容格式化为被动形式(最好在显示之前)。 按照我目前的方法,我尝试使用“valueChanges”订阅字段

但这会导致递归,这是可以理解的。每次我更改subscribe字段中的值时,都会再次调用它

因此,我的问题是,如何在显示之前直接编辑输入

导出类NewPaymentComponent实现OnInit{
付款方式:FormGroup;
构造函数(){}
ngOnInit():void{
this.paymentForm=新表单组({
amountFormatted:new FormControl('0.00',验证器。必需)
});
this.paymentForm.get('amountFormatted').valueChanges.subscribe((change)=>{
这是付款单
.get('amountFormatted')
.setValue(此.formatAmount(更改));
});
}
formatAmount(输入:字符串):字符串{
//…方法体被省略
返回“已更改”;
}
}
在另一次尝试中,我尝试使用
pipe
map
更改该值。然后在
点击
写入正确的路径,但不用于字段

this.paymentForm
.get('amountFormatted')
.水管(
map((val)=>(val=this.formatAmount(val)),
点击((更改)=>console.log('onTap',更改))
)
.subscribe();

考虑将
emitEvent
设置为
false
,如下所示:

this.paymentForm.get('amountFormatted').valueChanges.subscribe((change)=>{
这是付款单
.get('amountFormatted')
.setValue(此.formatAmount(更改),{emitEvent:false});
});

非常感谢!这解决了我的问题。我没有注意到
选项
字段:)