无法在Angular 2中的父组件模板中使用子组件

时间:2018-04-09 17:48:50

标签: javascript angular angular-cli

虽然我在app.module.ts中的FavoriteComponent数组中添加了declarations[]但我仍然收到错误:

  

意外指示' FavoriteComponent'由模块导入   '的AppModule&#39 ;.请添加@NgModule注释。

favorite.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'favorite',
  template: '<span class="glyphicon glyphicon-star"></span>'  
})
export class FavoriteComponent   {    

}

courses.component.ts

import { Component, OnInit, transition } from '@angular/core';

@Component({
  selector: 'courses',
  templateUrl:  './courses.component.html'
  ,
  styleUrls: ['./courses.component.css'],

})
export class CoursesComponent  {
  text= `
    Lorem Ipsum is sumply a dummy text   Lorem Ipsum is sumply a dummy text 
  `
}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import{FormsModule} from '@angular/forms';

import { AppComponent } from './app.component';
import { CoursesComponent } from './courses/courses.component';
import { SummaryPipe } from './summary.pipe';
import { FavoriteComponent } from './favorite/favorite.component';


@NgModule({
  declarations: [
    AppComponent,
    CoursesComponent,
    SummaryPipe,
    FavoriteComponent
  ],
  imports: [
    BrowserModule,FormsModule
  ],
  exports: [

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

0 个答案:

没有答案