akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 877 forks source link

Intercepting HTTP request within ServerSourceData #837

Open mardrof opened 6 years ago

mardrof commented 6 years ago

Hi everyone, I have some problem with Smart Table module. I need to intercept HTTP request to add some headers. My interceptor works perfectly with services until I add Ng2SmartTableModule into component module imports. Below you can see part of the code

tags.module.ts

  imports: [
    CommonModule,
    Ng2SmartTableModule /* if I remove this line, interceptor works */
  ],
  declarations: [TagsComponent, TagsListComponent],
  providers: [
    TagsService
  ]
})
export class TagsModule { }

app.module.ts

  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpClientModule,
    BrowserAnimationsModule,
    AppRoutingModule,

    NgbModule.forRoot(),
    ThemeModule.forRoot(),
    CoreModule.forRoot(),
  ],
  bootstrap: [AppComponent],
  providers: [
    { provide: APP_BASE_HREF, useValue: '/' },
    { provide: HTTP_INTERCEPTORS, useClass: BaseHttpInterceptor, multi: true},
  ],
})
export class AppModule {}

I'm using latest version (1.3.4) of library. Could you help me to solve this problem?

alexandr-efimov commented 6 years ago

Met the same situation. Assumption reason: You module, that declares table component(tags.module.ts) doesn't have interceptor provider Solution (possible not ideal, but works for me):

  providers: [
    UserTableComponent,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: TokenInterceptor,
      multi: true
    },

in your module (not only in root app.module/some other) declare interceptor provider. Then it works :)

mardrof commented 6 years ago

I will check your solution next week :) Thank you for response :)