Angular js - Show message if ng-repeat is empty

后端 未结 7 2017
别那么骄傲
别那么骄傲 2020-12-13 19:08

The following AngularJS application is working with ng-repeat and an applied filter. A certain applied filter leaves no values left. How can I display a notification?

<
7条回答
  •  萌比男神i
    2020-12-13 19:39

    I would go with very simple CSS approach:

    HTML:

    • #{{item.id}} Item
    • There are no matching items.

    CSS:

    li + .no-items {
        display: none;
    }
    

    So basically li.no-items is only visible if there are no other LI's and hidden otherwise. I think this is better for performance than introducing one more watcher with ngShow/ngHide.

    Demo: http://jsfiddle.net/z9daLbLm/5/

提交回复
热议问题