Angularjs过滤器不为空 [英] Angularjs filter not null
问题描述
试图筛选出具有一定的属性,不是空的项目因此,对于:
Trying to filter out items with a certain property that is not null So for:
var details = [{name:'Bill', shortDescription: null}, {name:'Sally', shortDescription: 'A girl'}]
我想只显示一华里;在一个突破口。这是我没有成功尝试
I would like to only show one li; the one for sally. This is what I have tried with no success
<ul>
<li ng-repeat="detail in details | filter:{shortDescription:'!'}">
<p>{{detail.shortDescription}}</p>
</li>
</ul>
任何想法,我怎么能做到这一点,而无需创建自定义过滤器?或者,即使如此,什么自定义过滤器会是什么样子?
Any idea how I can do this without creating a custom filter? Or even so, what the custom filter would look like?
推荐答案
据<一个href=\"https://github.com/angular/angular.js/issues/11573\">https://github.com/angular/angular.js/issues/11573对角> = 1.4,则建议使用''它匹配任何原始除空/未定义。
According to https://github.com/angular/angular.js/issues/11573 for Angular >= 1.4, the recommendation is to use '' which matches any primitive except null/undefined.
<ul>
<li ng-repeat="detail in details | filter:{shortDescription: ''}">
<p>{{detail.shortDescription}}</p>
</li>
</ul>
这篇关于Angularjs过滤器不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!