Angular JS - ng-repeat and loop conditions

前端 未结 2 535
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 11:30

Hey i have this piece of code:

{{i}}

It works but i would like to put extra conditions

相关标签:
2条回答
  • 2020-12-10 11:30

    Use the ng-if statement

    <div ng-repeat="i in values">
       {{i}}
       <div ng-if="i !== 0"></div>
    </div>
    
    0 讨论(0)
  • 2020-12-10 11:43

    Use ng-if (or ng-show):

    <div ng-repeat="i in values">
       <div ng-if="i !== 0"></div>
    </div>
    

    Attached to the element, this will decide whether to display it or not.

    Documentation for ng-if can be found here.

    However, if you want to only do something if you are looping the first or last item, you can use $first and $last properties of ng-repeat as well. These are documented with ng-repeat. And can be used like this:

    <div ng-repeat="i in values">
       <div ng-if="$first"></div>
    </div>
    
    0 讨论(0)
提交回复
热议问题