Angular 4.2.x拦截器没有被执行

Angular 4.2.x interceptor is not being executed

我正在使用
- Angular 4.2.4

我正在尝试使用以下 angular 代码拦截服务

import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from 
'@angular/common/http';
import { Observable } from 'rxjs/Rx';
export class LocalHttpClientInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): 
Observable<HttpEvent<any>> {
  const username = 'me';
  const password = 'blahblah';
  const authReq = req.clone({headers: req.headers.set('Authorization', 
'Basic ' + btoa(username + ':' + password))});
  return next.handle(authReq);
  }
 }

在模块文件中

import { LocalHttpClientInterceptor } from './local-http-client-
interceptor';
  @NgModule({
   imports: [
   CommonModule,
   FormsModule,
   ReactiveFormsModule,
   MdAutocompleteModule,
   MdInputModule,
   MdIconModule,
   HttpModule,
   MdGridListModule,
   FlexLayoutModule
 ],
 declarations: [ UserSearchComponent, ObjectComponent],
 exports: [UserSearchComponent, ObjectComponent, FlexLayoutModule],
 providers : [{
 provide: HTTP_INTERCEPTORS,
 useClass: LocalHttpClientInterceptor,
 multi: true,
 }, UserSearchService, LocalHttpClientService, StorageService]
})
 export class SharedModule { }

问题: 我能够看到拦截函数定义处的调试点被触发,但是在拦截内部执行一些服务调用代码后没有被调用。

我正在使用来自 @angular/http 的 angular http 来使用 get,options,post 方法调用服务

根据官方更改日志,包 @angular/common/http 可从 angular 4.3.0 获得,而您正在使用 4.2.4 我认为这可能是原因。并尝试使用 @angular/common/http 而不是 @angular/http

如何在angularhttps://angular.io/guide/http

中使用新的httpClient

这是工作中的 plunker https://plnkr.co/edit/wtl8EIaCpov6ScwBfPWX?p=preview

有关更多更改日志,请访问 https://github.com/angular/angular/blob/master/CHANGELOG.md