zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    多任务异步操作在爬虫中的应用
    selenium怎样避免被服务器检测
    python查看文件夹下所有文件
    使用selenium实现站长素材图片采集
    云打码接口
    django的请求生命周期
    django中间件
    Python之Hello World的条件输出实例
    项目要部署到远程的服务器:
    饭侠main.js
  • 原文地址:https://www.cnblogs.com/sugartang/p/14727766.html
Copyright © 2011-2022 走看看