INF*_*SYS 3 angular-http angular-http-interceptors angular
我Http之前使用的是Angular 模块,并且该方法res.json()用于正常工作.我最近尝试过,HttpClient但res.json()似乎没有工作.只有使用res作品才能告诉我http客户端发生了什么变化.
return this.client.get('https://swapi.co/api/people/1/')
.map((res:Response) => {
return res.json(); // using maps to filter data returned form the http call this json dosn't work with http client
}).map(data => {
return data; // using maps of maps to filter data returned form the map
}).flatMap((jedi) => this.http.get(jedi['homeworld'])
.map(res => {
return res.json().name; // using flat maps to combine data returned from two observables into one
}).catch((error:any) => Observable.throw(error.json().error || 'Server error')));
Run Code Online (Sandbox Code Playgroud)
我切换到http客户端,因为新的拦截器可以指针欢迎谢谢
是的,这是因为默认情况下新的http客户端res.json()隐式调用,而您自己不需要手动调用.这是commit的引用:
JSON是假定的默认值,不再需要显式解析
请参阅角度4中的HTTP和HTTPClient之间的差异?更多细节.
| 归档时间: |
|
| 查看次数: |
10881 次 |
| 最近记录: |