0

I want to call a function, when the last item is about to be displayed.

<div *ngFor="let el of arr">
   {{ el }}
<div>

arr is defined as

public arr = [1,2,3,4];

How could I call a funtion after the last item is about to be displayed?

This would be interesting for large data structures with thousands of elements.

Operator
  • 85
  • 1
  • 7
  • https://stackoverflow.com/a/35405648/13258211 –  Jul 10 '20 at 09:38
  • I want to call a function just once after all items have been displayed. This would not work for me – Operator Jul 10 '20 at 09:52
  • Please use index in ngFor. *ngFor="let item of items; let i = index" you can calculate the length of arr. than compare it with index, once you have the length-1 equal to index than call your expected method. – surendra kumar Jul 10 '20 at 09:53
  • Ah, gotcha. You could maybe use `onload` together with the index to fire a function when the last element in the array has loaded. –  Jul 10 '20 at 10:10
  • Hey Mike, ```onload``` does not work on ```div``` – Operator Jul 10 '20 at 10:19

0 Answers0