如何在过滤器在 ng-repeat 中不返回任何内容时显示消息 - AngularJS [英] How to show a message when filter returns nothing in ng-repeat - AngularJS

查看:28
本文介绍了如何在过滤器在 ng-repeat 中不返回任何内容时显示消息 - AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当过滤器(ng-repeat)上没有返回任何项目时,我想显示一个 div(消息).

I would like to show one div(message) when no items returned on filter(ng-repeat).

过滤是基于选择框(ng-model)发生的.并且某些选择选项没有结果,此时用户应该能够在同一位置阅读消息.我可以在这里使用 ng-show/hide 吗?怎么样?

Filter is happening based on select box (ng-model). And there are no results for some select options, at that time user should be able to read a message at same place. Can I use ng-show/hide here? How?

谢谢,

推荐答案

您还可以将过滤后的数组保存在一个变量中,然后在 ng-show 表达式中使用该变量:

You can also save your filtered array in a variable and then use that variable inside the ng-show expression:

<select ng-model="shade" ng-options="shade for shade in shades"></select><br>
<ul>
    <li ng-repeat="c in filteredColors = (colors | filter:shade)">{{c.name}}</li>
</ul>
<div ng-show="!filteredColors.length">No colors available</div>

您可以在这个 plunker 中看到它的实际效果.

You can see it in action in this plunker.

这篇关于如何在过滤器在 ng-repeat 中不返回任何内容时显示消息 - AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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