Angular2 如果在表单标签中使用 ngModel,则必须设置 name 属性或表单 [英] Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form
问题描述
我从 Angular 2 收到这个错误
<块引用>core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18由以下原因引起:如果在表单标签中使用了 ngModel,则名称必须设置属性或表单控件必须在 ngModelOptions 中定义为独立".
示例 1:
示例 2:
<td *ngFor="let lag of ce.lags"><div class="form-group1"><输入名称=名称"[(ngModel)]=lag.name"[ngModelOptions]={standalone: true}";类=表单控制"模式=[0-9]*(\.[0-9]+)?"需要>
</td>
这就是我使用表单标签的方式:
如果使用 ngForm,则所有具有 [(ngModel)]="
的输入字段都必须有一个属性 name 带有值.
I am getting this error from Angular 2
core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18 caused by: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.
Example 1:
<input [(ngModel)]="person.firstName" name="first">
Example 2:
<input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
<td *ngFor="let lag of ce.lags">
<div class="form-group1">
<input name="name" [(ngModel)]="lag.name" [ngModelOptions]="{standalone: true}" class="form-control" pattern="[0-9]*(\.[0-9]+)?" required>
</div>
</td>
This is how I use form tag:
<form #f="ngForm" (ngSubmit)="onSubmit()">
If ngForm is used, all the input fields which have [(ngModel)]=""
must have an attribute name with a value.
<input [(ngModel)]="firstname" name="something">
这篇关于Angular2 如果在表单标签中使用 ngModel,则必须设置 name 属性或表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!