0
我一直在学习Angular2。我观察到'指令'标签在RC版本的@Component元数据中用于引用其中的另一个组件。但是在Ang 2.1.0版中没有与它相关的'指令'标签。我现在应该如何引用另一个组件?Angular2中指令的替换是什么?
我一直在学习Angular2。我观察到'指令'标签在RC版本的@Component元数据中用于引用其中的另一个组件。但是在Ang 2.1.0版中没有与它相关的'指令'标签。我现在应该如何引用另一个组件?Angular2中指令的替换是什么?
你应该申报declarations
的@NgModule
元财产directives
,如下图所示(如directives
元物业已经从@Component
装饰去掉)
@NgModule({
imports : [ BrowserModule, .... ],
declarations : [
AppComponent,
DashboardComponent //<<<### here it is another component or directive,
HighlightDirective //<<<### directive declared with @Directive decorator
],
providers : [ ],
bootstrap : [ AppComponent ]
})
export class AppModule { }
以获得更多信息可以参考https://angular.io/docs/ts/latest/guide/ngmodule.html
非常感谢micronyks的回应,但这是唯一的方法吗?我不能在组件内使用标签进行引用吗?我看到在@Component内部有一个'entryComponent'标签,但它不像指令那样工作。请澄清。 –
entryCompoent在您想要动态注入组件时使用。但对于静态cmp你可以用图示的方式去... – micronyks
谢谢micronyks! –