angular11 报错 ERROR Error: If ngModel is used within a form tag, either the name attribute must be set or the form

angular 报错 ERROR 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}">

创建
表单的时候,系统默认会创建一个”FormGroup"的对象。用带有“ngModel"的”“标签时

遇到这个问题 通常是因为 input 标签没有 name 添加上name=”xxxName”就可以哦了~~

例如:ZORRO中的nz-select

<form nz-form nzLayout="vertical" #f="ngForm" se-container>

  <se label="AAA">
    <nz-select [(ngModel)]="form.AAA" nzMode="multiple">
      <nz-option [nzValue]="data" [nzLabel]="data" *ngFor="let data of AAADatas"></nz-option>
    </nz-select>
  </se>
  
</form>

改为

<form nz-form nzLayout="vertical" #f="ngForm" se-container>

  <se label="aaa">
    <nz-select [(ngModel)]="form.aaa" nzMode="multiple" name="aaa">
      <nz-option [nzValue]="data" [nzLabel]="data" *ngFor="let data of aaaDatas"></nz-option>
    </nz-select>
  </se>
  
</form>
posted @   糖~豆豆  阅读(348)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
Live2D
欢迎阅读『angular11 报错 ERROR Error: If ngModel is used within a form tag, either the name attribute must be set or the form』
点击右上角即可分享
微信分享提示