voliva / angular2-interceptors

79 stars 20 forks source link

An error in angular4 #28

Open baihech opened 7 years ago

baihech commented 7 years ago

我在google搜索到了一个angular2-interceptors的配置例子,我用这个例子配置了拦截器,但是工作起来有个异常,请问您准备支持angular4么? I google search for an angular2-interceptors configuration example, I use this example configuration of the interceptor, but there is an exception to work, ask you ready to support the angular4? Angular2 Http拦截器 Interceptor 实现

@angular/cli编译代码时会提示provideInterceptorService不存在,但是当你修改了某些代码后,watch到重新编译时,代码可以正确运行了。。

@Angular/cli Compile the code will prompt provideInterceptorService does not exist, but when you modify some of the code, watch to re-compile, the code can run correctly.

app.module.ts

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpModule,
    CoreModule,
    LayoutModule,
    SharedModule.forRoot(),
    RoutesModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [Http]
      }
    })
  ],
  providers: [HttpInterceptor,
    **provideInterceptorService**([
      HttpInterceptor
    ])
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}
baihech commented 7 years ago

我找到了一个简单方法实现的拦截器。 I found a simple way to implement an interceptor。 Angular2 Http Interceptor 自定义拦截器