How to set http call timeout in angularjs 4?

人走茶凉 提交于 2019-12-08 19:41:31

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

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());
} 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!