4

I am new to Angular 4 and I am learning through the docs from angular.io.

When I am trying to add a checkbox to a Dynamic Form, the form is not being loaded.

This is the link to my code - Link

I have added 2 Check box groups and 1 Radio button group, but only the first check box group is loading and rest of the elements are not loading.

1

1 Answer 1

1

You have to set the [formControlName]="question.key" to the input tag and not to the div element. You can see the error with the Chrome WebDeveloperTools: No value accessor for form control with name: 'flightRules'.

<div [id]="question.key" *ngSwitchCase="'checkbox'" >
  <span *ngFor="let opt of question.options">
    <label>
      <input [type]="question.controlType" [value]="opt.value" [formControlName]="question.key">
      {{opt.value}}
    </label>
  </span>
</div>

<div [id]="question.key" *ngSwitchCase="'radio'">
  <span *ngFor="let opt of question.options">
    <label>
      <input [type]="question.controlType" [value]="opt.value" [formControlName]="question.key">
      {{opt.value}}
    </label>
  </span>
</div>

See the forked link: Link

Sign up to request clarification or add additional context in comments.

2 Comments

@alexander..thanks for the information..based on the console log error how did you conclude that the change was in the formcontrol (this will help in my future debugging pursoses)..
I have read that error somewhere in the past. FYI: You can use formControlName only on directives which implement ControlValueAccessor (see link)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.