Angular 2 Component is not part of any NgModule

前端 未结 9 2049
予麋鹿
予麋鹿 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 19:02

    Same issue here and i solved it.

    1) You create your component

                import { Component } from '@angular/core';
                @Component({
                  moduleId:module.id,
                  selector: 'page-home',
                  templateUrl:'HomeComponent.html',
                })
                export class HomeComponent  { }
    

    2) You should declare it in app.module.ts

                import {HomeComponent}  from './Components/Pages/Home/HomeComponent';
                ...
                declarations: [ 
                    AppComponent,
                    HomeComponent
                ],
    

    And the problem is fixed.

    0 讨论(0)
  • 2020-12-08 19:08

    The mentioned error is produced when you do not include associated components in main "module" section of the respective component. So ensure that the component is mentioned there in module.

    0 讨论(0)
  • 2020-12-08 19:08

    In my case, I was using angular material dialog. I have forgot to include the dialog in NgModule. Dialog need to be there in both NgModule and entryComponents.

    0 讨论(0)
提交回复
热议问题