TypeError:无法读取HttpInterceptor的undefined属性'ngOriginalError'

时间:2019-03-18 07:24:37

标签: angular angular-http-interceptors

我正在尝试在HttpRequest和HttpResponse的范围内添加微调器。在app.module.ts的提供程序列表中添加名为HttpServiceInterceptor的服务后,抛出ngOriginalError。

http.interceptor.ts:

Collections.sort(yourArrayList, new YourComparator());

app.module.ts:

import {Injectable} from '@angular/core';
import {
    HttpRequest,
    HttpHandler,
    HttpEvent,
    HttpInterceptor
  } from '@angular/common/http';
  import { Observable } from 'rxjs/Observable';
  import 'rxjs/add/operator/finally';
import { CommonService } from '../../services/common.service';

@Injectable()
export class HttpServiceInterceptor implements HttpInterceptor{

    constructor(private commonService : CommonService){}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    let url : string =request.url;
    let subUrl : string =url.substring(url.lastIndexOf("/"),url.length);
    if(subUrl =='/searchData' || subUrl =='/searchReportsData' || subUrl =='/searchRerunData' || subUrl =='/reRun'){
        this.commonService.startSpinner();
        return next.handle(request).finally(()=>this.commonService.stopSpinner());
    }else{
        return next.handle(request); 
    }

  }
}

CommonService(包含已实现的方法):

 providers: [
    { provide: HTTP_INTERCEPTORS, useClass: HttpServiceInterceptor, multi: true } ]

错误:

startSpinner() { 
        console.log("start spinner");
        this.startspinner.next();
    }

    stopSpinner() {
        console.log("stop spinner");
        this.stopspinner.next();
    }

0 个答案:

没有答案