- 问题:表单使用数据双向绑定时出错
- 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.
- 原因
- 表单使用双向数据绑定 ngModule 时会给此标签创建一个 FormControl 对象,并以该标签的 name 属性为标识,没有则会报错
- 解决:根据提示有两种解决方案
- 给该标签添加 name 属性
- 阻止该标签创建 FormControl 对象。[ngModuleOptions]="{standalone:true}"
表单问题记录
最新推荐文章于 2023-07-23 17:11:21 发布