Catch duplicates and ignore them inside ng-repeat's track by without a filter (AngularJS)

82 Views Asked by At

I'm having some issues using ng-repeat with track by because sometimes duplicate data comes in (same user) because the user was pushed down in the date ordered list (API side) after a newer entry has been pushed to the beginning of the array.

I wonder if it's possible to do something like (pseudo code)

try {
     render(element)
} catch (DuplicateElementException $e) {
     // ignore element
     return;
}
1

There are 1 best solutions below

0
On

The best solution is to transform your array before you attach it to the DOM. This is common behaviour in front end application to transform the data received by the backend before displaying it.

Just loop through your data and remove the duplicate and generate the array you NEED for the HTML output