【问题标题】:AngularJS Quiz appAngularJS 测验应用程序
【发布时间】:2015-02-07 19:58:46
【问题描述】:

我有两个分数字段。一个在右边,第二个在最后一个“完成”页面。第一个工作正常,但是当我转到完成页面时,完成分数不计入最后一个问题的最后点击。

这是整个应用程序的 plunkr:http://plnkr.co/edit/wTQHOz

 $scope.answerClick = function(index){
    $scope.clicks++;

    if($scope.clicks === 4){
        resultService.score = $scope.score;
        $location.path('/finish');
    }

    if(index === $scope.currentQ.answer){
        $scope.score++;
    }
    $scope.move(+1);


};

【问题讨论】:

  • 打开浏览器的错误控制台。修复它显示的所有错误。不要要求我们重新创建整个项目。

标签: angularjs html


【解决方案1】:

这个问题与 Angular 无关,这是一个逻辑错误。您的结果不计入最后一个问题的原因是代码的顺序错误。 (我回答了你的最后一个问题,但也没有发现这个错误..)

if(index === $scope.currentQ.answer){
    $scope.score++;
}

if($scope.clicks === 4){
    resultService.score = $scope.score;
    $location.path('/finish');
}

您应该首先验证当前问题的答案,然后检查它是否是最后一个。

【讨论】:

  • 感谢您的帮助,我知道这是明显的错误
猜你喜欢
  • 2017-07-15
  • 2013-04-26
  • 2015-12-10
  • 2018-07-09
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-30
相关资源
最近更新 更多