@for control-flow block

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.

0
Subscribe to my newsletter

Read articles from Oliver Waterkamp directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Oliver Waterkamp
Oliver Waterkamp