【问题标题】:No value accessor for form control with name: ''没有名称的表单控件的值访问器:''
【发布时间】:2018-05-02 11:38:05
【问题描述】:

错误错误:表单控件没有值访问器,名称为:'sNo'

在我的 DOM 中没有找到 formCONtrolName

组件端

this.form = new FormGroup({
 'sNo': new FormControl,
 'question': new FormControl,
 'options': new FormGroup({
   'op': new FormControl,
  })
    });

HTML 方面

<form [formGroup]="form">
      <div *ngFor="let data of currentQuestionsValue">
        <div *ngFor="let d of data.items ">
          <strong formControlName="sNo"> {{ d.sno }}). </strong>
          <span formControlName="question">{{ d.question}}</span>
          <div>
            <form formGroupName="options">
              <label *ngFor="let key of objectKeys(d.options)" formControlName="op">
                <input type="radio" name="option" [value]="d.options[key]">
                <span>{{ d.options[key] }}</span>
              </label>
            </form>
          </div>
        </div>
      </div>
    </form>

【问题讨论】:

标签: angular forms typescript angular-reactive-forms


【解决方案1】:

您不能将formControlName 指令应用于strong 标记。它必须应用于表单字段标记(selectinputtextarea)或实现CustomValueAccessor 接口的自定义组件。

【讨论】:

    【解决方案2】:

    您应该在输入上使用 formControlName="sNo" 而不是 strong

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多