I'm a sieucapvipropeople.
I want to set value for a formControl in a formGroup when another formControl in this fromGroup has changed value
I try this but catch error: 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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.