[英]Angular: How to change value of formgroup when formgroup has changed value?
I'm a sieucapvipropeople.我是一个 sieucapvipropeople。
I want to set value for a formControl in a formGroup when another formControl in this fromGroup has changed value当此 fromGroup 中的另一个 formControl 更改值时,我想为 formGroup 中的 formControl 设置值
I try this but catch error: maximum call stack size exceeded angular
:我尝试了这个但发现错误: maximum call stack size exceeded angular
:
this.formGroup.get('DepreciationConfigInfo')?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((depreciationConfigInfo) => { this.formGroup.get('DepreciationConfigInfo')?.get('DepreciationEnd')?.setValue(5) })
This is the FormGroup, I try to catch the event DepreciationPeriod or DepreciationStart change value:这是 FormGroup,我尝试捕获事件 DepreciationPeriod 或 DepreciationStart 更改值:
DepreciationConfigInfo: new UntypedFormGroup({ DepreciationPeriod: new UntypedFormControl(), DepreciationStart: new UntypedFormControl(), DepreciationEnd: new UntypedFormControl({value: '', disabled: true}), }),
Tks.谢谢。
this.formGroup.get('DepreciationConfigInfo')
?.valueChanges.pipe(takeUntil(this.destroy$))
.subscribe((depreciationConfigInfo) => {
this.formGroup.get('DepreciationConfigInfo')
?.get('DepreciationEnd')?.setValue(5, { emitEvent: false })
})
Do not trigger an event, this way the form control doesn't react to the change.不要触发事件,这样表单控件就不会对更改做出反应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.