AngularJS NG重复手柄空单的情况下 [英] AngularJS ng-repeat handle empty list case
问题描述
我认为这将是一个很平常的事情,但我找不到如何处理它AngularJS。比方说,我有事件的列表,并希望与AngularJS输出他们,那么这就是pretty容易:
I thought this would be a very common thing, but I couldn't find how to handle it in AngularJS. Let's say I have a list of events and want to output them with AngularJS, then that's pretty easy:
<ul>
<li ng-repeat="event in events">{{event.title}}</li>
</ul>
但我怎么处理案件时,列表是空的?我想有一个消息框在地方名单是像无事件或类似。这将接近的唯一的事情是 NG-开关
与 events.length
(我怎么检查是否空当一个对象,而不是一个数组?),但真正唯一的选择我?
But how do I handle the case when the list is empty? I want to have a message box in place where the list is with something like "No events" or similar. The only thing that would come close is the ng-switch
with events.length
(how do I check if empty when an object and not an array?), but is that really the only option I have?
推荐答案
您可以使用 ngShow 。
<li ng-show="!events.length">No events</li>
请参阅例如。
或者你也可以使用 ngHide
<li ng-hide="events.length">No events</li>
请参阅例如。
有关对象,你可以测试 Object.keys 。
For object you can test Object.keys.
这篇关于AngularJS NG重复手柄空单的情况下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!