Trung BìnhAngular iconAngular

`switchMap`, `mergeMap`, `concatMap`, `exhaustMap` khác nhau thế nào trong Angular?

switchMap hủy request trước và lấy request mới nhất, phù hợp search/autocomplete.

Ví dụ search box:

typescript
results$ = this.search.valueChanges.pipe(
  debounceTime(300),
  distinctUntilChanged(),
  switchMap(term => this.http.get<SearchResult[]>("/api/search", { params: { q: term } })),
)

mergeMap chạy song song, concatMap xếp hàng giữ thứ tự, exhaustMap bỏ qua trigger mới khi request cũ đang chạy.

Chọn operator theo concurrency semantics.

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

Mở danh sách Angular