0

Angular code

public radioForm: FormGroup = this.formBuilder.group({
        selectedMainAnswer: this.formBuilder.array([], [Validators.required])
    });


const control = <FormArray>this.radioForm.controls['selectedMainAnswer'];
        for (const s of this.selectionControl) {
            const selectedForm: FormGroup = this.formBuilder.group({
                label: [s.label, [Validators.required]],
                key: [s.key, [Validators.required]]
            });
            control.push(selectedForm);
        }

Html

<span
          class="g-radio-wrapper"
          formArrayName="selectedMainAnswer"
          *ngFor="let selection of radioForm.get('selectedMainAnswer')['controls']; let i = index"
        >
          <div [formGroupName]="i">
            <input
              type="radio"
              value="selection.value.key"
              id="radio-{{ i }}-{{ index }}"
              name="radio-type-{{ index }}"
              class="g_input-radio--block"
            />
            <label for="radio-{{ i }}-{{ index }}" class="g_label-radio g_label-radio--horizontal">{{
              selection.value.label
            }}</label>
          </div>
    </span>

How to get user selected radio button value, I have tried below code

this.claimRadioForm.get('selectedMainAnswer') as FormArray;

But above I am getting all info instead only the selected one.

2
  • 1
    FormArray is not suitable for holding radio button selection. You should consider another way. See this post. Commented Nov 25, 2020 at 9:09
  • ok thanks, I should use (change) then, I was looking some form array method which can give all selected :( Commented Nov 25, 2020 at 9:51

0

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.