, :
import 'rxjs/add/operator/timeout';
this.http.post('myurl',
body, {headers: headers})
.timeout(2000)
.map(res => res.json())
.subscribe((stuff) => {
//Do stuff
}, (errorResponse: any) => {
//Manage error
});
****** Angular >= 4.3 Rxjs >= 5.2.2 ******
RXJS 5.2 timeout pipe. , lettable ( , lettable).
Angular 4.3 HttpClientModule, - HttpModule.
:
import {timeout} from 'rxjs/operators/timeout';
let headers: HttpHeaders = new HttpHeaders();
headers.append('Content-Type', 'application/json');
let body = {something: 'my_value'};
this.http.post('myurl',
body, {headers: headers})
.pipe(
timeout(2000)
)
.subscribe((stuff: any) => {
//Do stuff
}, (errorResponse: HttpErrorResponse) => {
//Manage error
});