Angular
angular/control-flow
Templates use the built-in @if, @for and @switch blocks, not the *ngIf, *ngFor and *ngSwitch directives deprecated in v20.
drobnastatycznefe-angular
Dlaczego
NgIf, NgFor and NgSwitch are deprecated since Angular 20 with the intent to remove them in a later major. The built-in blocks need no CommonModule import, type-narrow inside @if, make track mandatory-by-habit in @for, and give an @empty branch for lists.
Poprawka
Run ng generate @angular/core:control-flow to migrate a project, then review the result. By hand: *ngIf="user as u" becomes @if (user; as u) { … }, *ngFor="let item of items; trackBy: byId" becomes @for (item of items; track item.id) { … } @empty { … }, and [ngSwitch] becomes @switch (x) { @case (…) { … } }.
Przykłady
<!-- bad -->
<li *ngFor="let item of items">{{ item.name }}</li>
<!-- good -->
@for (item of items; track item.id) {
<li>{{ item.name }}</li>
} @empty {
<li>No items yet.</li>
}Źródła
Fakty
- Identyfikator
angular/control-flow- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
angular- Tylko w projektach z
angular- Uczy jej skill
fe-angularAngular components- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain angular/control-flow