How should I modify the response to an HTTP request and easily access it before return it out from Observable?

前端 未结 6 471
春和景丽
春和景丽 2021-02-01 23:42

I\'m upgrading to Angular to version 5, I was using @angular/http before and now I need to update to @angular/common/http and use HttpClient

I a

6条回答
  •  天涯浪人
    2021-02-01 23:56

    As per my consideration you can call function of that service in your success responce and process your data in function and return it to back it.

    return this.http.get(url, {headers: this.headers}).map(
          (response: Response) => {
            const data = response.json();
            return this.processData(data);
          }
        ).catch(
          (error: Response) => {
            return Observable.throw(error);
          }
        );
        
    public processData(data : any){
      //process your data
      return data;//this is processed data
    }

提交回复
热议问题