我在 Angular 中有应用程序,我只有一个 HttpClientModule,但是当我在构造函数中提供 HttpClient 时,如下所示:
export class UserService {
constructor(private http: HttpClient /** <---- this one is ok, and requests are intercepted */) {
const i='i';
}
但在另一个模块中我也有类似的构造函数
export class TableComponent implements OnInit {
...
...
constructor(private http: HttpClient /** <---- this one is not ok, and requests are not intercepted */) {
}
我的 app.module
@NgModule({
declarations: [AppComponent],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptorRefresh,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true,
},
],
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
AppRoutingModule,
MainAppModule,
TableModule,
表格模块内容
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {TableHeaderComponent} from './table-header/table-header.component';
import {TableComponent} from './table/table.component';
import {TablePaginationComponent} from './table-pagination/table-pagination.component';
import {TableFilterComponent} from './table-filter/table-filter.component';
@NgModule({
declarations: [TableHeaderComponent, TableComponent, TablePaginationComponent, TableFilterComponent],
imports: [
CommonModule,
],
exports: [TableHeaderComponent, TableComponent, TablePaginationComponent, TableFilterComponent],
})
export class TableModule {
}
主应用模块
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {UsersComponent} from './users/users.component';
import {MainAppRoutingModule} from './main-app-routing.module';
import {LayoutComponent} from './layout/layout.component';
import {ThemeModule} from '../../@theme/theme.module';
import {NbCardModule} from '@nebular/theme';
import {Ng2SmartTableModule} from 'ng2-smart-table';
import {TableModule} from '../table/table.module';
@NgModule({
declarations: [UsersComponent, LayoutComponent],
imports: [
CommonModule, MainAppRoutingModule, ThemeModule, NbCardModule, Ng2SmartTableModule, TableModule,
],
})
export class MainAppModule {
}
我究竟做错了什么?