Angular 2 Component is not part of any NgModule

前端 未结 9 2088
予麋鹿
予麋鹿 2020-12-08 18:12

i\'m upgrading my Angular 2 project from RC5 to 2.0.0. I get this Error

Unhandled Promise rejection: Component LoginComponent is not part of any NgM

9条回答
  •  佛祖请我去吃肉
    2020-12-08 18:49

    Make it sure that your component is imported in app.module.ts. In my case that it was the reason where I forgot to include the component in the declaration

    @NgModule({
      declarations: [
        AppComponent,
        HomeComponent,
        IndexComponent
      ],
      imports: [
        BrowserModule, FormsModule, HttpClientModule, RouterModule.forRoot(routes)
      ],
      exports: [RouterModule],
      providers: [],
      bootstrap: [AppComponent]
    })
    

    Also make sure you restart server when new modules and components are added while ng serve it is also a reaosn when this problem occur. So, the basic solution is to quit the server and ng serve again.

提交回复
热议问题