NG-重复滤波器QUOT;显示所有的"如果没有选择的过滤项 [英] ng-repeat filter "show all" items if no filter selected
问题描述
我有一个使用℃的
菜单通过一堆过滤国家。 NG-重复
过滤器;选择>
I have an ng-repeat
filter that uses a <select>
menu to filter through a bunch of countries.
例如:
<div class="col-md-3 col-sm-6" ng-repeat="item in listings | filter: { location: locationFilter }">
我怎样才能让这个如果没有被选中,它会自动显示所有的国家呢?而且,只有开始过滤一次,某一个国家选择?
How can I make it so that if nothing is selected, it automatically shows ALL the countries? And only starts filtering once a particular country is selected?
我敢肯定,这可能是一个简单的问题,但我很新的这一点,并不能找到如何做到这一点。
I'm sure this is probably a simple question but I am quite new to this and couldn't find how to do it.
谢谢!
推荐答案
如果过滤前pression返回未定义
,那么过滤器将不适用。所以,你可以不喜欢以下内容:
If the filter expression returned undefined
, then the filter would not apply. So, you could do something like the following:
<div ng-repeat="item in listings | filter:(!!locationFilter || undefined) && {location: locationFilter}">
{{item}}
</div>
( !! locationFilter
手柄,falsy和
未定义
值)
(!!locationFilter
handles ''
, falsy and undefined
values)
这篇关于NG-重复滤波器QUOT;显示所有的&QUOT;如果没有选择的过滤项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!