Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I thought this would be a very common thing, but I couldn't figure out 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>

But how do I handle the case when the list is empty? I want to have a message box in a 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?

1 Answer

0 votes
by (106k points)

To handle the case when the list is empty you can use ngShow.

<li ng-show="!events.length">No events</li>

Or you can also use ngHide.

<li ng-hide="events.length">No events</li>

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer
+1 vote
1 answer

Browse Categories

...