虽然我在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 { }