methuselah methuselah - 3 months ago 14
AngularJS Question

ng-if does not validate function

Why does ng-if not validate the function I pass through it as either true or false? The div element is not displayed even if the condition is met.

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>

Answer

To answer your original question, you are returning a string instead of a number result to compare.

Also you defined a function that expects a parameter from where I think you want to get categorie scores. You should use it or remove the parameter.

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