您的当前位置:首页正文

错误angular2 Error: If ngModel is used within a form tag...

2024-11-30 来源:个人技术集锦

Error: 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}">

input 标签没有 name
添加上name=”xxxName”

<input placeholder="phone" [(ngModel)]="person.phone" #personPhone = "ngModel" maxlength="11"  required >

修改后

<input placeholder="phone" [(ngModel)]="person.phone" #personPhone = "ngModel" maxlength="11" name="phone"   required >

无报错

显示全文