Trung BìnhAngular iconAngular

Control flow mới `@if`, `@for`, `@switch` khác `*ngIf`, `*ngFor` thế nào?

Control flow block là cú pháp template built-in, không cần import directive và dễ type-check hơn.

Ví dụ:

html
@if (user(); as u) {
  <h2>{{ u.name }}</h2>
} @else {
  <app-login />
}

@for (item of items(); track item.id) {
  <app-row [item]="item" />
} @empty {
  <p>No data</p>
}

Từ Angular v20, NgIf, NgFor, NgSwitch đã deprecate, nên code mới nên dùng block syntax.

Xem toàn bộ Angular cùng filter theo level & chủ đề con.

Mở danh sách Angular