我有這個表單陣列:
this.chavesNfeForm = new FormArray([
new FormGroup({
chave: new FormControl(""),
})
]);
我在我的應用程式中使用這樣的:
<form [formGroup]="chavesNfeForm" *ngIf="this.nfReferenciadaForm.value.referenciada==1" >
<ng-container *ngFor="let chaves of chavesNfeForm.controls; let i = index">
<div class="row">
<div class="col-8">
<mat-form-field>
<mat-label><i class="fas fa-key"></i> Chave NF-e </mat-label>
<input matInput required formcontrolName="chave">
</mat-form-field>
</div>
</div>
</ng-container>
</form>
這樣我就可以根據需要擁有多種和動態的表單,讓用戶能夠根據需要添加或洗掉。
但是,當我嘗試輸出表單的值以供以后使用時,我什么也沒得到,表單上沒有存盤一個值。
我不知道我在這里做錯了什么。(目前使用 Angular 8 和 Typescript)
uj5u.com熱心網友回復:
嘗試使用 formControl 而不是 formcontrolName
// With form control
<form
[formGroup]="chavesNfeForm"
*ngIf="this.nfReferenciadaForm.value.referenciada == 1"
>
<ng-container *ngFor="let chaves of chavesNfeForm.controls; let i = index">
<div class="row">
<div class="col-8">
<mat-form-field>
<mat-label><i class="fas fa-key"></i> Chave NF-e </mat-label>
<input matInput required [formControl]="chaves.get('chave')" />
</mat-form-field>
</div>
</div>
</ng-container>
</form>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/527586.html
