I want to skip the item in ng-repeat using ng-if

2.5k views Asked by At

I am trying to use ng-if in ng-repeat for implementing Accordions. Based upon the condition value, the ng-repeat should skip some items in ng-repeat.

E.g. If the item.condition is true then only it should display accordion. The code below is what I have so far and it is not working. Does it look right?

     <accordion close-others="true">
          <accordion-group is-open="isopen" ng-repeat="item in items | limitTo:2" ng-if="item.condition == "true"",ng-init="isopen=2">
                  <accordion-heading>
          {{item.label}}
            <i class="pull-right glyphicon"
                         ng-class="{'icon-arrow-up': isopen, 'icon-arrow-down': !isopen}"></i>
                  </accordion-heading>
              </accordion-group>
          </accordion>
1

There are 1 answers

5
Pankaj Parkar On BEST ANSWER

Your ng-if contain double extra quotes, It should be ng-if="item.condition == true", Also remove the , from the accordion element

Also you could minimize your condition to ng-if="item.condition" so then expression will return true and false on item.condition variable evaluation.

Markup

<accordion close-others="true">
    <accordion-group is-open="isopen" ng-repeat="item in items | limitTo:2" 
       ng-if="item.condition" ng-init="isopen=2">
        <accordion-heading>
            {{item.label}}
            <i class="pull-right glyphicon" ng-class="{'icon-arrow-up': isopen, 'icon-arrow-down': !isopen}"></i>
        </accordion-heading>
    </accordion-group>
</accordion>