Does someone know how to use RxJS do
operator on observer returned by angular's HttpClient.get
method?
Versions:
- angular: 5.2.1
- rxjs: 5.5.6
With this version of angular I can't do this:
import { HttpClient } from '@angular/common/http';
...
constructor(
private http: HttpClient,
) { }
...
this.http.get<Item>(url)
.do(res => console.log(JSON.stringify(res)))
.share();
Instead I have to add new steps with pipes. I can do it with switchMap
, map
or share
, but I can't figure out how to do it with do
.
I found out that I can do import { _do } from 'rxjs/operator/do';
, but when I'm trying to use it like this:
this.http.get<Item>(url)
.pipe(_do(res => console.log(JSON.stringify(res)))
or like this:
const observable = this.http.get<Item>(url);
observable.pipe(_do(observable, res => console.log(JSON.stringify(res)}));
I'm getting error:
[ts] The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.