我基本上是在尝试为name(表单的type属性)分配一个值,但没有得到赋值,这给了它独立的问题
<div *ngFor="let a of UserFormArray">
<form #f="ngForm" (ngSubmit)="sender(f)" name="FormName">
{{a.name}}
<input type={{a.type}} [name]=a.name ngModel #awda="ngModel" required>
Name:
<input name="FirstName" ngModel #FirstName="ngModel" required> LastName:
<button>Submit</button>
</form>
</div>
错误:错误错误:如果在表单标记中使用ngModel,则必须设置name属性或表单 控件必须在ngModelOptions中定义为“独立”。
答案 0 :(得分:0)
您提到了表单元素的name
属性。
<div>
<form #f="ngForm" (ngSubmit)="sender(f)">
<input name="FirstName" #FirstName="ngModel" [(ngModel)]="a" required> Firstname : {{FirstName.value}}
<br/>
<input name="LastName" #LastName="ngModel" [(ngModel)]="b" required>
LastNme : {{LastName.value}}
<br>
<button>Submit</button>
</form>
</div>