I am currently working on an angular 4 application and encountering an error:
Error:Component HomeComponent is not part of any NgModule or the module has not been imported into your module.
My setup includes a HomeModule and a HomeComponent. Now, I am unsure whether I should refer to HomeModule or HomeComponent in the AppModule. The main goal is for the user to be directed to home.component.html upon clicking the Home menu item.
The code for App.module is as follows:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http'
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { TopbarComponent } from './topbar/topbar.component';
import { FooterbarComponent } from './footerbar/footerbar.component';
import { MRDBGlobalConstants } from './shared/mrdb.global.constants';
import { AppRoutingModule } from './app.routing';
import { HomeModule } from './Home/home.module';
@NgModule({
declarations: [
AppComponent,
FooterbarComponent,
TopbarComponent,
NavbarComponent
],
imports: [
BrowserModule,
HttpModule,
AppRoutingModule,
HomeModule
],
providers: [MRDBGlobalConstants],
bootstrap: [AppComponent]
})
export class AppModule { }
The code for HomeModule is as follows:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeComponent } from './home.component';
@NgModule({
imports: [
CommonModule
],
exports: [HomeComponent],
declarations: [HomeComponent]
})
export class HomeModule { }
The code for HomeComponent is as follows:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}