I want to skip an element in ng-repeat using ng-if

I am trying to use ng-if in ng-repeat to implement Accordions. Based on the value of the condition, ng-repeat should skip some elements in ng-repeat.

eg. If item.condition is true, then only it should display the accordion. The code below is what I have and it does not work. Does this 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> 
+6
source share
1 answer

Your ng-if contains double extra quotes, it must be ng-if="item.condition == true" . Also remove from the accordion element

In addition, you can minimize your condition to ng-if="item.condition" , after which the expression will return true and false in item.condition .

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> 
+5
source

Source: https://habr.com/ru/post/989837/


All Articles