Angular2.0报错If ngModel is used within a form tag, either the name attribute

09-29 15:49:20   来源:shikezhi   评论: 点击:

core umd js:3462 EXCEPTION: Error in template hero-form component html:6:13 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
core.umd.js:3462 EXCEPTION: Error in template/hero-form.component.html:6:13 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}">
 
 
core.umd.js:3464 ORIGINAL EXCEPTION: 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}">
 
 
 
原因:Angular2规定,当在表单中使用 [(ngModel)] 时,必须要定义 name 属性。没有name属性就会报上面的错误
 
解决办法:给表单标记添加name属性即可            

相关热词搜索:Angular2 0 错误

上一篇:Angular2.0报错:Unhandled Promise rejection: Failed to load..Zone: 下一篇:Angualr2.0报错TypeError: Cannot read property 'form' of undefined
分享到: 收藏