将路由组件的选择器留在原位有什么缺点吗?

时间:2018-04-24 14:00:10

标签: javascript angular typescript

在Angular routing documentation - Add heroes functionality部分的说明中说:

  

进行一些小的但必要的改变:

-Delete the selector (routed components don't need them).
-Delete the <h1>.

似乎将选择器留在原位是个好主意,以便组件可以在路由和非路由上下文中使用?

将它留在原地有什么缺点吗?

演示中使用的组件的文档示例实际上删除了@Component装饰器中的选择器,如下面CrisisCenterComponent示例所做的那样(直接从路由器文档中获取):

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

 @Component({
   template: `<p>Welcome to the Crisis Center</p>`
 })
 export class CrisisCenterHomeComponent { }

因此,在这种情况下,假设我们重构应用程序并将CrisisCenterComponent放在共享模块中,并在多个视图/页面中使用该组件,我们有时需要使用元素名称(Selector),有时使用路由器。删除selector会使这不可能吗?

1 个答案:

答案 0 :(得分:1)

将选择器留在组件中没有任何缺点。