Ich arbeite an Angular Reactive Formen. Anfangs habe ich ein Formarray in Formgroup. danach schiebe ich formgroup in formarray, um die Formularsteuerung dynamisch hinzuzufügen. Ich bekomme ein Problem beim Binden dieses Steuerelements mit formControlName. Ich erhalte diese Fehler: keine Kontrolle mit Pfad: 'controlArray -> 0 -> value'Problem beim Registrieren von Kontorl mit Formular in reaktiven Kurvenformen
hier ist der Code meiner Komponentenklasse:
ngOnInit(){
this.reviewForm = this.fb.group({
'controlArray': new FormArray([])
});
this.showDefaultForm();
}
Zuerst erhalte ich Daten in formsDb, dann ich Ich suche nach dem letzten Standardformular.
showDefaultForm(){
for(let form of this.formService.formsDb){
if(form.formName==this.formService.defaultForm.formName){
this.selectedForm = form;
this.addForm();
}
}
}
addForm(){
for (let control of this.selectedForm.controlsArr){
(<FormArray>this.reviewForm.get('controlArray')).push(this.fb.group([{
controlType: control.controlType,
label: control.label,
value: ''
}]));
}
}
Hier mein Template-Code ist:
<form [formGroup]="reviewForm" (ngSubmit)="onSubmit()">
<div class="example-label">
<span class='block'>
<div formArrayName="controlArray">
<div *ngFor="let control of reviewForm.get('controlArray').controls; let i = index">
<div [formGroupName]="i">
<table>
<tr>
<span *ngIf="control.value">
<td>
<label>{{control.value.label}}</label>
</td>
<td><span *ngIf="control.value.controlType == 'select'">
<md-select placeholder="{{control.value.label}}" formControlName="value">
<md-option *ngFor="let option of control.value.options; let j=index"
[value]="option">{{control.value.options[j]}}</md-option>
</md-select>
</span></td>
<td> <span *ngIf="control.value.controlType == 'text'">
<md-form-field class="example-full-width">
<input mdInput type="text" placeholder="{{control.value.placeholder}}" formControlName="value" >
</md-form-field>
</span></td>
</span>
</tr>
</table>
</div>
</div>
</div>
</span>
</div>
</form>
Gibt es eine Frage in meinem Template-Code, Bitte helfen. Danke
Welche "this.selectedForm" Variable hat? –
es hat Formulardaten, d. H. Formularname und Formularsteuerelemente. Seine Klasse ist: Exportklasse FormData { Konstruktor (public formName: String, öffentliche SteuerelementeArr: Control []) {} } –
Was ist 'this.showDefaultForm()'? – Alex