AngularJS ng-repeat handle empty list case

后端 未结 10 2255
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 16:47

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, t

10条回答
  •  遥遥无期
    2020-11-30 17:23

    Here's a different approach using CSS instead of JavaScript/AngularJS.

    CSS:

    .emptymsg {
      display: list-item;
    }
    
    li + .emptymsg {
      display: none;
    }
    

    Markup:

    • ...
    • No items found

    If the list is empty,

  • , etc. will get commented out and will become a comment instead of a li element.

提交回复
热议问题