如果定义了属性,则使用angular ng-repeat

时间:2014-06-25 17:57:29

标签: angularjs angularjs-ng-repeat

我试图通过数组进行ng-repeat,但是如果属性未定义则需要隐藏。

我试着这样做:

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

这是我尝试做的一个基本方面:

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

谢谢!

2 个答案:

答案 0 :(得分:1)

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

尝试测试person.last而不仅仅是'last'。 我使用ng-show而不是ng-if。

答案 1 :(得分:0)

如果你想隐藏行,那么mccainz的答案就可以了。如果您想要从DOM中删除它们,请创建一个过滤器:

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

HTML

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

JSFIddle