HttpClientModule
是現(xiàn)有的 HttpModule
的改進版,是 angular v4.30版本新增的模塊,增加了一些新的功能,比如攔截器, progress events等等
新的HttpClientModule
位于:
import { HttpClietModule } from '@angular/commom/http'
具體的文章參考:
- 使用 RxJS新操作符
ShareReplay()
避免重復的請求 - 使用 RxJS操作符
forkJoin()
將多個http請求合并 - 使用 RxJS操作符
SwitchMap()
將第一次請求的結果作為第二次請求的一部分 - 使用 RxJS操作符
SwitchMap()
將多次請求的結果都保留下來, 關于SwitchMap的用法可以參考 Deep Dive Into The RxJs switchMap Operator - How Does it Work ? A Less Well-Known Use Case (selector functions) 這篇文章 - 使用 RxJS操作符
catch()
進行異常錯誤處理
- A Taste From The New Angular HTTP Client HttpClient的一些特點簡介
- JSON as default
- Interceptors Support
- Progress events
Angular Authentication: Using the Http Client and Http Interceptors - 使用
HttpClient
實現(xiàn)驗證攔截,很詳細的教程,使用到了angular-jwt
The New HTTP Client in Angular 4.3 如何從HttpModule 升級到 HttpClientModule 模塊
JWT Interceptor with Angular HttpClient jwt中使用攔截器
當然第一篇文章更加的詳細