繁体   English   中英

Angular: formgroup改变值后如何改变formgroup的值?

[英]Angular: How to change value of formgroup when formgroup has changed value?

我是一个 sieucapvipropeople。

当此 fromGroup 中的另一个 formControl 更改值时,我想为 formGroup 中的 formControl 设置值

我尝试了这个但发现错误: 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) })

这是 FormGroup,我尝试捕获事件 DepreciationPeriod 或 DepreciationStart 更改值:

 DepreciationConfigInfo: new UntypedFormGroup({ DepreciationPeriod: new UntypedFormControl(), DepreciationStart: new UntypedFormControl(), DepreciationEnd: new UntypedFormControl({value: '', disabled: true}), }),

谢谢。

this.formGroup.get('DepreciationConfigInfo')
      ?.valueChanges.pipe(takeUntil(this.destroy$))
        .subscribe((depreciationConfigInfo) => {
          this.formGroup.get('DepreciationConfigInfo')
          ?.get('DepreciationEnd')?.setValue(5, { emitEvent: false })
        })

不要触发事件,这样表单控件就不会对更改做出反应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM