1

I'm working on a form that has a formArrayName in which I want to make use of a radio button. The problem is that all these radio buttons have the same name so when I'm clicking one, all the other radio buttons turn off.

If I give the radio button a name with an index (name[i]) I get the error message:

platform-browser.umd.js:1900 ORIGINAL EXCEPTION: If you define both a name and a formControlName attribute on your radio button, their values must match. Ex: <input type="radio" formControlName="food" name="food">

I can't find out how to fix this. I can't give the index to the init function because the index of the array can change. Below is an example of my code:

Edit: Made a Plunker example: http://plnkr.co/edit/o2ZxAFsuhD0F7OKevqei?p=preview

Anyone able to help me?

3 Answers 3

2

You need to let angular set the name property of input:

<input type="radio" [attr.name]="'sex' + i" value="male"> male
<input type="radio" [attr.name]="'sex' + i" value="female"> female
Sign up to request clarification or add additional context in comments.

1 Comment

Updated my question with a Plunker example. Your solution does not seem to work.
1

Leaving out the name property fixed the issue for me.

Comments

-1

It seems technically impossible without using multiple form elements.

Comments

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.