admin管理员组文章数量:1405145
I have a table with the ng-repeat property that populates data ing from a WS, I hide the last record because I dont need it with ng-hide="$last". Now there was an update to the WS and I need to hide the last 2 records but I dont know how to do this.
I have something like this.
<table>
<tr ng-repeat="d in exportData.result" ng-hide="$last">
...code....
</tr>
</table>
Any help on this.
I have a table with the ng-repeat property that populates data ing from a WS, I hide the last record because I dont need it with ng-hide="$last". Now there was an update to the WS and I need to hide the last 2 records but I dont know how to do this.
I have something like this.
<table>
<tr ng-repeat="d in exportData.result" ng-hide="$last">
...code....
</tr>
</table>
Any help on this.
Share Improve this question asked Mar 17, 2016 at 16:01 kennechukennechu 1,4229 gold badges25 silver badges37 bronze badges5 Answers
Reset to default 5Replace
d in exportData.result
To:
d in (exportData.result.slice(0, exportData.result.length-2))
Another way is to do the same thing in your controller.
Why not use Angular's limitTo
filter on your ngRepeat?
<tr ng-repeat="d in exportData.result | limitTo:quantity">
And then in your controller update the quantity to reflect your new desired value
$scope.quantity = $scope.exportData.result.length - 2;
I'd call a function from the ng-repeat
:
<table>
<tr ng-repeat="d in getTruncatedArray()">
...code....
</tr>
</table>
In you Controller:
$scope.getTruncatedArray = function() {
return exportData.result.slice(0, exportData.result.length - 2));
}
Explanation
I'd suggest you to call a method instead of writing your "filter" directly in the HTML. Calling a method will keep your HTML clean and it makes your "filter" easy to update/modify.
One another dirty way :)
<tr ng-repeat="d in exportData.result track by $index" ng-show="$index < exportData.result.length -2">
...code....
</tr>
Dont forget that ng-show/hide create dom elements, it only play with css visibility, filtering your array as @nashter suggest avoid that behaviour.
See fiddle
<div ng-controller="MyCtrl">
<div ng-repeat="line in lines">
<div class="preview" ng-hide="((lines.length-2)==$index)||($index==$last)">{{$index}} </div>
</div>
本文标签: javascriptHide last 2 records from angular ngrepeatStack Overflow
版权声明:本文标题:javascript - Hide last 2 records from angular ng-repeat - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744878458a2630058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论