How can I implement timeout for angular2+ http request

前端 未结 4 1617
迷失自我
迷失自我 2020-12-01 18:22

Here is just regular request looking like that:

this.people = http.get(\'http://localhost:3000/users\')
                  .map(response => response.json()         


        
4条回答
  •  春和景丽
    2020-12-01 18:49

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

    import { timeout } from 'rxjs/operators';

    getPeople(){
      return this.http.get(API_URL)
      .pipe(
          timeout(5000) //5 seconds
      );
    

提交回复
热议问题