I am trying to learn Angular and have run into what is probably a very simple problem.
I have written a child component for doing grid paging called "PageSelectorComponent". This component just takes a total record count and calculates and displays page links (no providers are used in this component). I have embedded this component inside another component called "TestComponent".
PageSelectorComponent and Test Component are included in the delarations portion of my app.module.ts file.
My issue is that I get the following error:
ERROR Error: Uncaught (in promise): Error: No provider for PageSelectorComponent!
If I add PageSelectorComponent to the providers section of the app.module.ts everything works fine except now I get two instances of the component. This causes my subscribe not to work.
I have looked over how PageSelectorComponent and TestComponent are declared but don't see a difference.
Why does the app complain about not listing PageSelectorComponent as a provider?
Here is the NgMoudle section of my app.modules.ts:
@NgModule({
declarations: [
AppComponent,
NavigationComponent,
HomeComponent,
PageSelectorComponent,
TestComponent,
],
imports: [
BrowserModule,
RoutingModule,
],
providers: [
PageSelectorComponent // App complains if I leave this out but now I get 2 instances of the component.
],
bootstrap: [AppComponent]
})
Here is the definition for PageSelectorComponent:
@Component({
moduleId: module.id,
selector: 'app-page-selector',
templateUrl: './page-selector.component.html',
styleUrls: ['./page-selector.component.css'],
})
export class PageSelectorComponent {
// member variables declared here
.
.
private static instanceNum: number = 0; // TOOD: debugging
constructor() {
PageSelectorComponent.instanceNum += 1;
console.log(`page-selector instance number ${PageSelectorComponent.instanceNum}`)
this.subject = new Subject();
}
Like I said, I think there is some really basic Angular thing I missed here. Any suggestions on where to look?
Thanks in advance!