为什么我的 ng-class 即使是 false 也会显示

Why does my ng-class display even when false

当用户猜错鱼的名字时,我正试图摇动一张图片。我正在使用条件 ng-class="{'shake':error}"。然而,即使答案是正确的,图像也会抖动。我不相信任何时候 $scope.error 都设置为 true。我在这里错过了什么?

codepen

我想你想要做的是 return guessIsCorrect 或 guessIsWrong 来自你的 compare 函数。

$scope.compare = function(guess) {
    guess = guess.replace(/\s/g, '').toLowerCase();
    var answers = [];
    answers.push($scope.name.replace(/\s/g, '').toLowerCase());

    currentAnimal.alts.forEach(function(alt) {
        answers.push(alt.toLowerCase().replace(/\s/g, ''));
    });
    //console.log(answers);
    //console.log("Guess: " + guess + "\n");
    //console.log("Answer: " + answers + "\n");

    for (var x = 0; x <= answers.length; x++) {
        if (guess === answers[x]) {
            return guessIsCorrect();
        }
        if (x === answers.length) {
            return guessIsWrong();
        }
    }

};