我有一个表单,在这个表单中,在这个窗体中,我有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
中的moreAccountInfo
为disabled
。
我写了这个代码:
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()
演示