Angularjs 过滤器不为空 [英] Angularjs filter not null

查看:39
本文介绍了Angularjs 过滤器不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图过滤掉具有不为空的特定属性的项目因此:

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?

推荐答案

根据 https://github.com/angular/angular.js/issues/11573 对于 Angular >= 1.4,建议使用 '' 匹配除 null/undefined 之外的任何原语.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆