@for control-flow block

@for control-flow block

A closer look to its track argument

I think the track argument is not described transparently enough in the official Angular documentation and I had a few questions about it that remained unanswered.

In the following article I tried to show you how the track-expression can be written.

Decision maker:

  • $index -> if collection doesn't change ( @for(todo of todos; track $index) {} )

  • unique id -> if collection changes ( @for(todo of todos; track todo.id) {} )

  • object reference -> if collection changes and no unique id ( @for(todo of todos; track todo) {} )

  • function -> ( @for(todo of todos; track myTrackByFunction) {} )

Hope, I could help you a little bit.