AngularJS ng-repeat handle empty list case

后端 未结 10 2296
隐瞒了意图╮
隐瞒了意图╮ 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:12

    With the newer versions of angularjs the correct answer to this question is to use ng-if:

    • ( No items in this list yet! )
    • {{ item }}

    This solution will not flicker when the list is about to download either because the list has to be defined and with a length of 0 for the message to display.

    Here is a plunker to show it in use: http://plnkr.co/edit/in7ha1wTlpuVgamiOblS?p=preview

    Tip: You can also show a loading text or spinner:

      
  • ( Loading... )
提交回复
热议问题