Angular 2 http service timeout?

10,741 views
Skip to first unread message

Carlos Esteban Lopez Jaramillo

unread,
Dec 16, 2015, 5:13:45 PM12/16/15
to AngularJS
Hi, i'm in a urgent need to get a `timeout` feature or function to limit the wait for a response from server, previously there was a way with the observable returned by http:
    this.http.post(url, JSON.stringify(json), {headers: headers, timeout: 1000})
        // .retry(2)
        // .timeout(10000, new Error('Tiempo de espera alcanzado.'))
        // .delay(10)
        // .map((res) => res.json())
        .subscribe(
          (data) => resolve(data.json()),
          (err) => reject(err)
        );

Unfortunately all the commented functions above have been deleted when updated to alpha.52, how am i supposed to get a timeout from the current http service?

Eric Martinez

unread,
Dec 16, 2015, 8:45:26 PM12/16/15
to AngularJS
Carlos, 

those operators/observables weren't removed. Now you must import them manually.

import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/timeout';
import 'rxjs/add/operator/delay';
import 'rxjs/add/operator/map';




this.http.post(url, JSON.stringify(json), {headers: headers, timeout: 1000})

         
.retry(2)

         
.timeout(10000, new Error('Tiempo de espera alcanzado.'))

         
.delay(10)

         
.map((res) => res.json())
       
.subscribe(
         
(data) => resolve(data.json()),
         
(err) => reject(err)
       
);

Carlos Esteban Lopez Jaramillo

unread,
Dec 17, 2015, 8:40:59 AM12/17/15
to AngularJS
Thank god, i'm using ionic 2 which uses currently alpha.52 of angular 2 and when i updated the changelog in ionic 2 didn't said nothing about this change.
Reply all
Reply to author
Forward
0 new messages