Angular2 timeout in http post request

后端 未结 3 2030

Is it possible to make a timeout of 3 seconds in a post request ? How ?

My code for the moment

this.http.post(\'myUrl\', 
    MyData, {headers: Myhe         


        
3条回答
  •  野的像风
    2021-01-17 11:38

    You might need to import timeout like so

    import 'rxjs/add/operator/timeout'

    I couldn't get it to work without that on rxjs 5.0.1 and angular 2.3.1

    Edit 20 April 2018

    please refrain from importing operators that way, in rxjs +5.5 you can import operators like this one with

    import { timeout } from 'rxjs/operators/timeout';
    // Use it like so
    stream$.pipe(timeout(3000))
    

    Please checkout this document which explains pipeable operators in great depth.

提交回复
热议问题