Angular directive with ng-repeat, ng-show “Show more” and lazy-load

后端 未结 1 1801
耶瑟儿~
耶瑟儿~ 2020-12-15 08:54

I use this directive, iterating over an array \"myArr\", filtering for a few conditions.



        
相关标签:
1条回答
  • 2020-12-15 09:27

    Use ng-if instead of ng-show.

    Unlike ng-show, falsey ng-if removes the element from the DOM.

    EDIT:

    Also, you can, in fact, use limitTo filter, which would make your code much cleaner:

    <div ng-init="limit = 2">
      <foo ng-repeat="item in items | limitTo: limit as results"></foo>
    </div>
    <button ng-hide="results.length === items.length" 
            ng-click="limit = limit +2">show more...</button>
    

    plunker

    0 讨论(0)
提交回复
热议问题