Mar
Mar

Reputation: 1606

How to create dynamic radio buttons with multiple options

I am trying to create a dynamic form with multiple radio button options and get selected values..

<form name="myForm" ng-submit="sendAnswers(question)">
      <ul>
        <li ng-repeat="question in questionForm.questions">
          <p>{{question.description}}</p>
          <ul>
            <li ng-repeat="option in question.options">
             <input type="radio" ng-model="question.answer" value="option.value">
             {{option.value}}
            </li>
          </ul>
        </li>
      </ul>
    <p><input type="submit" value="sendAnswers"></p>
 </form>

Problem is as I click on button, both options get selected..what am I doing wrong here?

Live example: http://plnkr.co/edit/aStk4SCHzAW0AKQuH7JE?p=preview

Thanks in advance!

Upvotes: 2

Views: 12528

Answers (1)

Joe Enzminger
Joe Enzminger

Reputation: 11190

Add a "name" parameter:

<input name="{{question.description}}" type="radio" ng-model="question.answer" value="option.value">

Also, you need to change "value" to {{option.value}}

<input name="{{question.description}}" type="radio" ng-model="question.answer" value="{{option.value}}">

Working Example

Upvotes: 3

Related Questions