With Angular 17+ the @for control-flow block accepts a track expression that supplies a stable identity key. This lets the renderer reuse existing DOM nodes when the underlying array is rebuilt, instead of throwing them away and recreating them.
bsTrackBy: 'id' obsolete.
ul inside the bs-list-groupbs-list-group-item is recreated
<bs-list-group>
@for (person of people; track person.id) {
<bs-list-group-item>
{{ person.firstName }} {{ person.lastName }}
</bs-list-group-item>
}
</bs-list-group>
import { Component } from '@angular/core';
import {
BsListGroupComponent,
BsListGroupItemComponent,
} from '@mintplayer/ng-bootstrap/list-group';
interface Person {
id: number;
firstName: string;
lastName: string;
}
@Component({
selector: 'my-track-by-demo',
templateUrl: './my-track-by-demo.component.html',
imports: [BsListGroupComponent, BsListGroupItemComponent],
})
export class MyTrackByDemoComponent {
protected people: Person[] = [
{ id: 1, firstName: 'Andy', lastName: 'Sharp' },
{ id: 2, firstName: 'Chelsea', lastName: 'Downs' },
];
}