Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ionic3如何在ErrorHandlerService中注入服务/提供者_Javascript_Angular_Ionic Framework - Fatal编程技术网

Javascript ionic3如何在ErrorHandlerService中注入服务/提供者

Javascript ionic3如何在ErrorHandlerService中注入服务/提供者,javascript,angular,ionic-framework,Javascript,Angular,Ionic Framework,问题: ======= 当我在ErrorHandlerService中注入ConfigService来祝酒时,给我一个错误:ErrorHandlerService.ts:36 发生错误:Error:Uncaught(承诺中):TypeError:无法读取未定义的属性“\u appLog” export class ErrorHandlerService implements ErrorHandler { private _appLog: ConfigService;

问题:

=======

当我在ErrorHandlerService中注入ConfigService来祝酒时,给我一个错误:ErrorHandlerService.ts:36 发生错误:Error:Uncaught(承诺中):TypeError:无法读取未定义的属性“\u appLog”

 export class ErrorHandlerService implements ErrorHandler {

      private _appLog: ConfigService;
      constructor (private injector: Injector) {
        setTimeout(() => {
          this._appLog = injector.get(ConfigService);
        }, 0);
      }
      handleError(error: Error | HttpErrorResponse) {

          if (error instanceof HttpErrorResponse) {
              if (!navigator.onLine) {
                console.log('Please, check your internet connection');

              } else if(error.status === 401){
                console.log(error.message);
                this._appLog.presentToast();

              }else {
                console.log(error.message);
              }
            } else {
              console.log('Not Http Error');
          }
          // Log the error anyway
          console.error('It happens: ', error);
      }  
    }


    @Injectable()
    export class ConfigService {

        constructor(private storage: Storage){
        }

        presentToast(){
            console.log("test");
        }
    }


 getUsers(){
        let promise = new Promise((resolve, reject) => {
            let apiURL = `${this.configS.apiRootV1}/users`;
            this.http.get(apiURL).toPromise()
                .then((res) => {

                    console.log(res);
                    resolve(res);

                }).catch(this.errorHandlerService.handleError);
        });
        return promise;
    }

在handleError函数中,“this”未定义。尝试使用“绑定”发送“this”的值:

.catch(this.errorHandlerService.handleError.bind(this.errorHandlerService));

在handleError函数中,“this”未定义。尝试使用“绑定”发送“this”的值:

.catch(this.errorHandlerService.handleError.bind(this.errorHandlerService));