Angular2组件,选择器不在html中

时间:2016-11-22 15:12:45

标签: angular typescript

在以下pluker http://plnkr.co/edit/MC7gO55TGkQTrxaJnJir?p=preview

在DashboardComponent类的文件

 Dashboard.Component.ts 

定义了一个带有选择器但在文件.html中的@component 没有选择器等效,你可以解释我怎么可能? 你没有被迫定义选择器标签?

3 个答案:

答案 0 :(得分:3)

DashboardComponent中使用了Router。路由器组件不需要selector属性。

答案 1 :(得分:2)

路由器使用ViewContainerRef.createComponent(),它不需要选择器来匹配HTML。另请参阅Angular 2 dynamic tabs with user-click chosen components以获取示例。

答案 2 :(得分:0)

Angular路由器允许您直接路由到组件 - 请查看app / app-routing.module.ts: { path: 'dashboard', component: DashboardComponent },

有关更多详细信息,请参阅此处的“添加路由”链接: https://angular.io/docs/ts/latest/tutorial/toh-pt5.html