没有用于表单控件的值访问器,名称为:''

时间:2018-05-02 11:38:06

标签: angular forms typescript angular-reactive-forms

  

错误错误:没有名称为'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>

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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