latenightwreck
latenightwreck

Reputation: 17

angular ng-repeat if property is defined

I'm trying to ng-repeat through an array, but need to hide if a property is undefined.

I tried doing to do is this:

<div ng-repeat="person in people | filter:search" ng-if="last == undefined">
    {{person.last}}, {{person.first}}
</div>

Heres a basic jsfiddle of what I'm trying to do:

http://jsfiddle.net/HB7LU/4556/

Thank you!

Upvotes: 0

Views: 624

Answers (2)

Jerrad
Jerrad

Reputation: 5290

If you want to just hide the rows, then mccainz's answer will work. If you want to actually remove them from the DOM, then create a filter:

$scope.fullNameFilter = function(person){
    return person.last;
};

HTML

<div ng-repeat="person in people | filter: fullNameFilter">

JSFIddle

Upvotes: 0

mccainz
mccainz

Reputation: 3497

<div ng-controller="MyCtrl">
<div ng-repeat="person in people | filter:search" ng-show="person.last">
    {{person.last}}, {{person.first}}
</div>

Try testing for person.last instead of just 'last'. I used ng-show instead of ng-if as well.

Upvotes: 1

Related Questions