Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set http call timeout in angularjs 4?

Tags:

angular

ionic3

I have seen in angularjs 4 official page (https://angular.io/guide/http) to set http call timeout but I did not find any reference. Has anyone tried to set it up?

Thank you

like image 221
Davide Dell'Olio Avatar asked Nov 18 '25 07:11

Davide Dell'Olio


2 Answers

If you are using RxJS version 6 and above the current syntax is this:

import { timeout } from 'rxjs/operators';
...
getUsers() {
   return this.http.post(API_URL, {headers: Myheaders})
      .pipe(
          timeout(5000) //5 seconds
      );
} 

Reference: https://rxjs-dev.firebaseapp.com/api/operators/timeout

like image 52
MatPag Avatar answered Nov 21 '25 06:11

MatPag


There is a timeout operator:

getUsers() {
   return this.http.post(this.baseUrl + "users", {headers: Myheaders})
         .timeout(3000, new Error('timeout exceeded'))
         .map(res => res.json());
} 
like image 41
bgraham Avatar answered Nov 21 '25 08:11

bgraham