- 背景:angular中使用form表单时报错。
报错信息: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.
- 原因:input使用双向绑定ngModel时,ng会给这个标签创建一个FormControl对象,并以input定义的name属性为标识。没有name属性会报错。
- 解决方案: 1、增加name属性。
2、不让ng创建FormControl对象。[ngModelOptions]="{standalone: true}"
If ngModel is used within a form tag, either the name attribute must be set or the form contro
最新推荐文章于 2023-03-15 21:36:04 发布