進出口新帶活性形式和進出口試圖使具有分量indicadores
與answers
:角2種活性形式無法找到控制
有了這個組件:
addAnswers(indicador: Indicador, answer?: any):void {
const indicadoresFormArray = <FormArray>this.customForm.controls['indicadores'];
let label = answer ? answer.label : '';
let value = answer ? answer.value : '';
let superi = 0;
for(let i = 0; i < indicadoresFormArray.length; i++) {
if(indicadoresFormArray.value[i].id == indicador.id) {
superi = i;
}
}
(<FormArray>(<FormGroup>(indicadoresFormArray).controls[superi])
.controls['answers']).push(
new FormGroup({
label: new FormControl(label),
value: new FormControl(value)
})
)
}
而且模板
<div *ngFor="let indicador of customForm.controls['indicadores'].controls">
<div class="row" *ngFor="let answer of indicador.controls['answers'].controls">
<div class="input-field col m5 s6"><input formControlName="label" placeholder="Etiqueta" /></div>
<div class="input-field col m5 s6"><input formControlName="value" placeholder="Valores" /></div>
<div class="input-field col m2 s12 center-align">
<button type="button" class="btn-floating waves-effect waves-light" (click)="addAnswer()"><i class="material-icons">add</i></button>
</div>
</div>
</div>
它總是拋出異常:
ERROR Error: Cannot find control with name: 'label'
ERROR Error: Cannot find control with name: 'value'
而且我沒有任何想法,爲什麼...
的console.log(indicadoresFormArray);
公共customForm:FormGroup; 構造(私人FB:FormBuilder){ this.customForm = this.fb.group({ 標籤:[空], 值:[ '',Validators.required] }) } 嘗試此 –