ng-if不验证函数

时间:2016-04-13 13:16:47

标签: javascript angularjs

为什么ng-if不验证我通过它的函数是真还是假?即使满足条件,也不会显示div元素。

controller.js

$scope.getCategoriseScore = function(profile) {
    var currentRating = this.profile.currentRating;
    if(currentRating >= 961 && currentRating <= 999) {
        var scoreRange = "excellent";
        return scoreRange;
    } else if(currentRating >= 881 && currentRating <= 960) {
        var scoreRange = "good";
        return scoreRange;
    } else if(currentRating >= 721 && currentRating <= 880) {
        var scoreRange = "fair";
        return scoreRange;
    } else if(currentRating >= 561 && currentRating <= 720) {
        var scoreRange = "poor";
        return scoreRange;
    } else if(currentRating >= 0 && currentRating <= 560) {
        var scoreRange = "very poor";
        return scoreRange;
    }
}

view.html

<div class="row" ng-if="getCategoriseScore() <= 961">
</div>

2 个答案:

答案 0 :(得分:2)

要回答原始问题,您将返回一个字符串而不是一个数字结果进行比较。

您还定义了一个函数,该函数需要一个我认为您想要获得分类分数的参数。您应该使用它或删除参数。

<div class="row" ng-if="getCategoriseScore(PROFILE) <= 961">

答案 1 :(得分:0)

n00b错误。这解决了它。

<div class="row" ng-if="profile.currentRating <= 961">
</div>