Angular2如果在表单标签中使用ngModel,则必须设置name属性或表单 [英] Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form

查看:63
本文介绍了Angular2如果在表单标签中使用ngModel,则必须设置name属性或表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Angular 2中收到此错误

I am getting this error from Angular 2

core.umd.js:5995例外:未捕获(承诺中):错误:app/model_exposure_currencies/model_exposure_currencies.component.html:57:18中出现错误 原因:如果在表单标签中使用ngModel,则名称中的任意一个 必须设置属性或表单 控件必须在ngModelOptions中定义为独立".

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()">

推荐答案

如果使用ngForm,则所有具有[(ngModel)]=""的输入字段都必须具有带有值的属性 name .

If ngForm is used, all the input fields which has [(ngModel)]="" must have an attribute name with a value.

<input [(ngModel)]="firstname" name="something">

这篇关于Angular2如果在表单标签中使用ngModel,则必须设置name属性或表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆