Reputation: 787
Scenario :
Code To write in Angular 6 :
return this._http.post(this.apiBaseUrl + "/api/login", body, options)
.timeoutWith(Constant.timeout, Observable.throw(new Error(Constant.timeoutMsg)))
.map(response => {
const result = response.json() as LoginResultModel;
if (result.AccessToken != null) {
this.setLoginToken(result);
return result;
} else {
return response;
}
});
Upvotes: 2
Views: 233
Reputation: 18369
Just use pipe
method and put both timeoutWith
and map
operators as functions as its parameters:
import { throwError } from 'rxjs';
import { map, timeoutWith } from 'rxjs/operators';
return this._httpClient.post<LoginResultModel>(this.apiBaseUrl + "/api/login", body, options)
.pipe(
timeoutWith(Constant.timeout, throwError(new Error(Constant.timeoutMsg))),
map(result => {
if (result.AccessToken != null) {
this.setLoginToken(result);
return result;
} else {
return response;
}
})
);
More about pipable operators in RxJS 6:
https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md
Note I also used HttpClientModule
, where you don't need to use response.json()
method, more about that here:
Upvotes: 3