TrackById / TrackByProp
Created by Daniele Morosinotto
Import
Usage
TrackById
For objects that have an id
property, use TrackById
to efficiently iterate through them in *ngFor
.
TrackByProp
If you need to specify a different property for tracking, use TrackByProp
.
API
Inputs for TrackById
ngForOf: NgIterable<T>
- An iterable containing objects with anid
property.
Inputs for TrackByProp
ngForOf: NgIterable<T>
- An iterable of objects.ngForTrackByProp: keyof T
- The property name for tracking objects (required).
Validation
- For
TrackById
, an error is thrown if the iterable’s objects don’t have anid
property. - For
TrackByProp
, an error is thrown if the specified property doesn’t exist on the iterable’s objects.