Reputation: 1422
An easy question from a noob in Angular.
I have my ng-repeat like this:
ng-repeat="f in drillDownList['D' +
d.merchMetrics.DEPT_NBR + 'CG' +
d.merchMetrics.CATG_GRP_NBR + 'C' +
d.merchMetrics.DEPT_CATG_NBR]
and I want to slice the last record because it's alway empty and it comes like that from the WS but I dont know how to achive this in AngularJS.
Upvotes: 0
Views: 706
Reputation: 6961
Use the limitTo
filter.
ng-repeat="f in drillDownList['D' + d.merchMetrics.DEPT_NBR + 'CG' + d.merchMetrics.CATG_GRP_NBR + 'C' + d.merchMetrics.DEPT_CATG_NBR] | limitTo:-1"
Alternatively, just show the last item in the list.
<div data-ng-bind="drillDownList['D' + d.merchMetrics.DEPT_NBR + 'CG' + d.merchMetrics.CATG_GRP_NBR + 'C' + d.merchMetrics.DEPT_CATG_NBR][drillDownList['D' + d.merchMetrics.DEPT_NBR + 'CG' + d.merchMetrics.CATG_GRP_NBR + 'C' + d.merchMetrics.DEPT_CATG_NBR].length-1]" </div>
Might I suggest that you do all that concatenation in the Controller? If you do it on the View side, it's going to execute every digest.
Upvotes: 1
Reputation: 3623
Inside ng-repeat
you have available a variable $last
.
example
<div ng-repeat="item in [1,2,3,4]">
<div ng-if="!$last">{{item}}</div>
</div>
See more https://docs.angularjs.org/api/ng/directive/ngRepeat
Upvotes: 2