javascript - angularjs ng-class with different conditions -
i have view shows data , want add class on list items in view.
<input type="text" class="filter" placeholder="search..." ng-model="search"> <ul> <li ng-repeat="item in items | filter:search | orderby:'date'"> {{ date }} {{ item.heading }}<button ng-click="deleteitem(item.id)"><i class='icon-trash'></i></button> </li> </ul>
i have variables called item.date , want compare variables today. here logic:
if (item.date - today <= 0) apply class1 if else (item.date - today > 0 && item.date - today <= 3) apply class2 , on
how can achieve angular? can put logic directly view or need define in controller?
thanks in advance
since have bit heavy comparisons make, suggest moving inside function rather having in html:
<li ng-class="getclass(item.date)" ng-repeat="item in items | filter:search | orderby:'date'">
js:
$scope.getclass = function(date){ /* comparison logic here*/ /* returs class name string */ }
Comments
Post a Comment