angular 2 - Injected service in http error handler

前端 未结 3 524
广开言路
广开言路 2020-12-06 14:16

I have a method handleError() like in the documentation https://angular.io/docs/ts/latest/guide/server-communication.html#!#error-handling

private handleErro         


        
3条回答
  •  余生分开走
    2020-12-06 14:47

    this in handleError in your case is probably not what you think it is.

    Try to do the following:

    this.http.get(url,
                  ApiRequest.ACCEPT_JSON)
                  .map(ApiHelper.extractData) 
                  .catch(this.handleError.bind(this)); // <-- add .bind(this)
    

提交回复
热议问题