Set timeout for HttpClient

I need to manage timeout of all backend request. This is my code…

    ...
    var httpHeaders = this.getHeader();
    return this.http.post(httpUrl, JSON.stringify(data), httpHeaders);
 

I tried to use timeout function but it is not present.

this.http.post(httpUrl, JSON.stringify(data), httpHeaders).timeout(10000);

What is the solution?

I get nervous when I see custom headers, because well more than half the time they’re unneeded at best and bugfood at worst. Make absolutely certain you need them. For example, if you’re setting Content-Type in there, don’t.

As for your main question, see the RxJS documentation about operators for general information, because timeout is a pipeable operator.