i'm implementing a rating feature in my ionic app. i created icon fonts so i could display the the stars as classes. I want to use the ngclass directive to conditionally set what the class is based on the rating.
for my question: Is my Logic and Syntax correct??
/* MODEL */
$scope.items = [{id: 1, name: 'foo', rating: 3 },{id: 2, name:'bar', rating: 4}]
...
/* CONTROLLER */
$scope.checkRating = function(rating) {
if (rating === 1){ return 'one-star' }
else if (rating === 2){ return 'two-star' }
else if (rating === 3){ return 'three-star' }
else if (rating === 4){ return 'four-star' }
else if (rating === 5){ return 'five-star' }
}
...
/* VIEW */
<ion-list>
<ion-item ng-repeat="item in items">
<h2>{{item.name}}</h2>
<p><span ng-class="checkRating(item.rating)"></span><p>
</ion-item>
</ion-list>