Angular 在处理多个组件中的 router-outlet 标签时,通过指令选择器来确定需要渲染的标签。在组件中,可以使用 select 属性来设置选择器。
示例代码:
在 app.component.html 中:
在 admin.component.html 中:
上面的代码中,app.component.html 中只有一个 router-outlet 标签,因此不需要指定选择器。而在 admin.component.html 中,我们通过 select 属性指定了选择器为 “admin”,这样 Angular 就会根据选择器来渲染对应的 outlet 标签。