如何使用多个选项创建动态单选按钮

时间:2015-03-08 17:23:34

标签: angularjs radio-button

我正在尝试使用多个单选按钮选项创建动态表单并获取选定的值..

<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>

问题是当我点击按钮时,两个选项都被选中..我在这里做错了什么?

实例:http://plnkr.co/edit/aStk4SCHzAW0AKQuH7JE?p=preview

提前致谢!

1 个答案:

答案 0 :(得分:3)

添加&#34;名称&#34;参数:

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

此外,您需要更改&#34;值&#34;到{{option.value}}

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

Working Example