Every time I try to import a component to another component (they are not siblings ) I got this error on console :
...
ERROR Error: "StaticInjectorError(AppModule)[LogsTableComponent -> FilterBarComponent]:
StaticInjectorError(Platform: core)[LogsTableComponent -> FilterBarComponent]:
NullInjectorError: No provider for FilterBarComponent!"
...
here is my app.module.ts file :
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { LogsTableComponent } from './components/logs-table/logs-
table.component';
import { FilterBarComponent } from './components/filter-bar/filter-
bar.component';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { HttpClientTestService } from './http-client-test.service';
@NgModule({
declarations: [
AppComponent,
FilterBarComponent,
LogsTableComponent,
],
imports: [
BrowserModule,
// HttpClientModule should be imported after BrowserModule.
HttpClientModule,
BsDatepickerModule.forRoot()
],
providers: [HttpClientTestService],
bootstrap: [AppComponent]
})
export class AppModule { }
Can anyone help me to know why this error is occurring and how to resolve it.
This may be the key phrase: "No provider for FilterBarComponent!". I suppose, you should add the FilterBarComponent to the "imports/providers (?)" array in the "AppModule" file.