Trung BìnhAngular iconAngular

Khi nào Angular app cần NgRx, Signal Store hoặc state management library?

Không phải Angular app nào cũng cần global state library. Local component state nên dùng signals; server stream/cache có thể giữ Observable trong service; feature state vừa phải có thể dùng service/store tự viết.

Pattern store nhỏ bằng signal:

typescript
@Injectable({ providedIn: "root" })
export class CartStore {
  private readonly _items = signal<CartItem[]>([])
  readonly items = this._items.asReadonly()
  readonly total = computed(() => this._items().reduce((sum, item) => sum + item.price, 0))
}

Cân nhắc NgRx/Signal Store khi state dùng chung nhiều route, mutation phức tạp, cần devtools/time travel, effect orchestration hoặc convention mạnh cho team lớn.

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

Mở danh sách Angular