HttpClientModule 和 使用RxJS来处理常用的H
2017-07-13 本文已影响281人
JamesSawyer
HttpClientModule 是现有的 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实现验证拦截,很详细的教程,使用到了angular-jwt -
The New HTTP Client in Angular 4.3 如何从HttpModule 升级到 HttpClientModule 模块
-
JWT Interceptor with Angular HttpClient jwt中使用拦截器
当然第一篇文章更加的详细