try to show items in ng-repeat, only if value of some key not empty.
This is code:
<a class="item" href="#" ng-repeat="e in events | orderBy:'match_time'" ng-if="e.match_timer !== NaN && e.match_status !== 'FT'">
e.match_timer looks like:
{
match_timer: ""
}
try to show items in ng-repeat, only if value of some key not empty.
This is code:
<a class="item" href="#" ng-repeat="e in events | orderBy:'match_time'" ng-if="e.match_timer !== NaN && e.match_status !== 'FT'">
e.match_timer looks like:
{
match_timer: ""
}
Share
Improve this question
asked Dec 20, 2014 at 11:59
n00b43677n00b43677
1872 silver badges16 bronze badges
3
-
1
try using
ng-if="e.match_timer !==''"
– Arjun Vachhani Commented Dec 20, 2014 at 12:06 - thanks, it works! I tried "" but it not working – n00b43677 Commented Dec 20, 2014 at 12:17
-
if you are using double quotes(") then you should use single quotes for directive like
ng-if='e.match_timer !==""'
or to escape double quotes(") you can use slash (\) – Arjun Vachhani Commented Dec 20, 2014 at 12:20
3 Answers
Reset to default 5in ng-if
you can write your condition like this
<a class="item" href="#" ng-repeat="e in events | orderBy:'match_time'" ng-if="e.match_timer !== '' && e.match_status !== 'FT'">
This way it will display only those elements which are non-empty for e.match_timer
and has other value then FT
You can check for the length of the string.
e.match_timer.length > 0 or e.match_timer > 0 if it is number.
Instead of ng-if
you should use a ng-filter, like this
Html:
<a class="item" href="#" ng-repeat="e in events | orderBy:'match_time' | filter:filterExpression">{{e.match_timer}}</a>
JS:
myApp.filter('filterExpression', function() {
return function (e) {
return typeof (e.match_timer) === 'string' && e.match_status !== 'FT'
};
});
Demo: http://jsfiddle/HB7LU/9381/