Angularjs的测验问题

时间:2014-07-31 05:15:01

标签: angularjs angularjs-ng-repeat

我使用angularjs创建测验应用程序并遇到一些问题 当我点击“下一步”时,选中的收音机不会重置

<div ng-repeat="answ in quiz.typical">
    <label ng-click="quiz.checkAnsw()">
    <input type="radio" name="answ{{quiz.qNum}}">                    
        {{answ.text}}                    
    </label>
</div>

Fiddle
如何重置检查无线电?

1 个答案:

答案 0 :(得分:2)

您可以为收音机设置值,然后通过ng-model

将它们绑定到属性
<div ng-repeat="answ in quiz.typical">
  <label ng-click="quiz.checkAnsw()">
    <input type="radio" name="answ{{quiz.qNum}}" ng-value="$index" ng-model="quiz.selectedAns" />
    {{answ.text}}
  </label>
</div>

并在控制器中,将quiz.selectedAns重置为undefined

this.changeQ = function(){
  this.qNum++;
  this.selectedAns = undefined;
};

JSFiddle: http://jsfiddle.net/zug5y/