See this Plunker for the solution I managed to come up with.
It might not be elegant, but it (mostly) works!
Basically, *ngFor
helpfully provides a handful of values, like index, even, odd, and fortunately enough, first and last booleans that evaluate to true for the respective iterations. First, you have to expose the values as local variables in the *ngFor
exactly as you would the index. Then, you have to get Angular to call the function from the template, which you can do as if you were binding a value to the template but with a tertiary conditional (that returns null for false evaluations).
<div *ngFor="let i of stuff; let l = last ">
{{ i }} {{ l === true ? callOnLastIteration() : null}}
</div>
I say "(mostly) works" because it seems that if you try to bind to a property inside of the *ngFor
-ed element, other than the one you are iterating on and then change value of said property inside of the function called at the last iteration, you'll get undesired behavior and errors from Angular's change propagation system. See the Plunker for details.