用可观察的方式实现rxjs超时

时间:2018-11-11 20:21:35

标签: angular http rxjs

我正在尝试通过可观察的http实施超时,但是我认为我没有正确处理请求。

import { HttpClient,HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/delay';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/timeout';


//POST form 
  submitForm(data,authToken){
    //console.log(data,authToken);
    const httpOptions = {
        headers: new HttpHeaders({
            'Accept': 'application/json, text/plain',
            'Content-Type':  'application/json',
            'Authorization': authToken
          })
 };
  return this.http.post(this.apisubmitFormUrl, JSON.stringify(data),
        httpOptions||{reportProgress:true})
        .retry(3)
        .timeout(15000)
        .delay(2000);

  }

在其他页面上

this.stemAPI.submitForm(this.submitData,this.reap.token).subscribe((result) =>{  
   //handle response
   }, (err) => 
    { 
   //handle error
 });

0 个答案:

没有答案