如何禁用角9中表单数组的控制项之一



我有一个表单,在这个表单中,在这个窗体中,我有formArray

InitialFrom(): void {
this.addElectricMoneyFG = this.fromBuilder.group({
hasAccountNumber: [this.showMoreInfo],
moreAccountInfo: ['', null],
description: [''],
locales: this.fromBuilder.array([]),
published: [false]
})

formArray:

selectedLanguage(langId): FormGroup {
return this.fromBuilder.group({
languageId: [langId],
name: [''],
moreAccountInfo: ['']
})

}

单击我想要的切换时,formArray中的moreAccountInfodisabled

我写了这个代码:

this.f.hasAccountNumber.valueChanges.subscribe(check => {
this.showMoreInfo = check;
if (check) {
this.f.locales['controls'][0]['controls']['moreAccountInfo'].enabled;
} else {
this.f.locales['controls'][0]['controls']['moreAccountInfo'].enabled;
}
this.f.locales.updateValueAndValidity();
this.cdRef.detectChanges()
})

它没有工作,抛出了这个错误:

this.f.locales.controls[0].controls.moreAccountInfo.disabled is not a function

您需要遵循此方法。

(<FormArray>this.testForm.get("locales")).controls[0].get('moreAccountInfo').disable()

如果要禁用整个形式的索引0。

(<FormArray>this.testForm.get("locales")).controls[0].disable()

演示

最新更新