How to import component into another root component in Angular 2

后端 未结 4 1793
夕颜
夕颜 2020-12-01 04:44

I am trying to import component from one file another root component file. it give error as ..

zone.js:484 Unhandled Promise rejection: Template parse

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 05:34

    For Angular RC5 and RC6 you have to declare component in the module metadata decorator's declarations key, so add CoursesComponent in your main module declarations as below and remove directives from AppComponent metadata.

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { AppComponent } from './app.component';
    import { CoursesComponent } from './courses.component';
    
    @NgModule({
      imports:      [ BrowserModule ],
      declarations: [ AppComponent, CoursesComponent ],
      bootstrap:    [ AppComponent ]
    })
    export class AppModule { }
    

提交回复
热议问题