Angularjs: ng-repeat, put a helper in ng-repeat to split recently downloaded data

When the page loads, the user is presented with a set of products, and then, when he clicks the button, products are added to the list. I am trying to find a way for Angular to put a line to separate products that have already been downloaded from a recently added one. I don’t want to manipulate the DOM directly, and I cannot push an empty string into the product array, because the length of the array is used somewhere else.

How can i do this?

Here is the basic bin

+4
source share
2 answers

I think you will need to track this yourself, in another property of $ scope (array). In your ng-repeat loop, check if $ index is in this array. If yes, add / show <hr>.

<... ng-repeat="..."> <span ng-show="showHr($index)"><hr></span> ... </...> 

The showHr () function should return true when you want to display <hr>.

You can also use ng-switch instead of ng-show.

+1
source

If you do not want the divisor after the last element, just use:

 <... ng-repeat="..."> <hr ng-show="!$last" /> ... </...> 

$ last is true if the repeated element is the last in the iterator.

+13
source

All Articles