【发布时间】:2017-07-29 18:49:40
【问题描述】:
我已经玩了 angular 2 几天了。我正在尝试将子选择器插入父模板。它应该很简单,但我一辈子都无法让它发挥作用。我收到以下错误:
“未处理的承诺拒绝:模板解析错误: 'child' 不是已知元素:"
我哪里出错了?有人能帮我摆脱痛苦吗?
//app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ChildModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
//app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
entryComponents: [ChildComponent]
})
export class AppComponent {
title = 'app works!';
}
<!-- app.component.html -->
<h1>
{{title}}
</h1>
<child></child>
//child.module.ts
@NgModule({
declarations:[ChildComponent]
})
export class ChildModule{}
//child.component.ts
@Component({
selector:'child',
templateUrl: './child.component.html'
})
export class ChildComponent{
}
<!-- child.component.html -->
<h1>child</h1>
【问题讨论】:
标签: angular angular2-directives