简体   繁体   中英

angularjs $index when ng-hide with ng-repeat

I have itemlist which need to display with serial no. i used $index with ng-repeat but when element is hide at that time index was increased.

Code i tried as follow:

<div ng-repeat="itemRow in salesitem" class="tableRow h7" ng-hide="itemRow.flagDeleted">
                    <div class="tableCell">{{$index}}</div>
                    <div class="tableCell">{{itemRow.name}}</div>
                    <div class="tableCell">{{itemRow.qty}}</div>
</div>

when itemRow.flagDeleted is True at that item will not display but index will be increased so next item serial no is going wrong.

Instead use a filter on the repeat:

<div ng-repeat="itemRow in salesitem | filter:{ 'flagDeleted' : false}" class="tableRow h7">
    <div class="tableCell">{{$index}}</div>
    <div class="tableCell">{{itemRow.name}}</div>
    <div class="tableCell">{{itemRow.qty}}</div>
</div>

http://plnkr.co/edit/VfFcbUJpoXG6mRkJSFYS?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM