I recently encountered an issue with my Angular 2.45 project that is written in Typescript. I added a new component to the routing module of my application and made sure to import it properly.
Upon starting the app, I was faced with the following error:
Unhandled Promise rejection: Component NewComponent is not part of any NgModule or the module has not been imported into your module. ; Zone: <root> ; Task: Promise.then ; Value: ZoneAwareError Error: Component NewComponent is not part of any NgModule or the module has not been imported into your module.
...
ZoneAwareError
This is what I have set up in my app's routing module:
const routes: Routes =
[
// common routes
{
path: 'NewComponent',
component: NewComponent
},
....
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
In addition, I included the new Component and RoutingModule in the declarations and imports array of my AppModule.
@NgModule({
imports: [
...,
AppRoutingModule,
],
declarations: [
....,
NewComponent
],
bootstrap: [AppComponent]
)}
export class AppModule {}
While this setup works for all other Components, the NewComponent does not function correctly. Any insights on what might be causing this issue?