Can not read property Intercept of undefined after upgrading ANGULAR CLI to latest

时间:2019-01-07 13:59:05

标签: angular angular-cli intercept

enter image description here

After upgrading angular cli to 7.0.2 , i am facing intercept of undefined error, when try to npm start , i also attached error screenshot with code

import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs';


@Injectable()
export class AuthInterceptor implements HttpInterceptor {
  public user;

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    if (localStorage.getItem('user') && JSON.parse(localStorage.getItem('user'))\['data'\]\['user'\]) {
      this.user = JSON.parse(localStorage.getItem('user'))\['data'\]\['user'\];
    }

    req = req.clone({
      headers: req.headers.set('Authorization', localStorage.getItem('token') ? localStorage.getItem('token') : '')
    });
    req = req.clone({ headers: req.headers.set('app_token', '51fec7b7-3abb-4743-8956-6b2fbbeae03f') });
    req = req.clone({ headers: req.headers.set('company_id', this.user && this.user.company_id ? this.user.company_id : '0') });
    return next.handle(req);
  }
}

0 个答案:

没有答案