【发布时间】:2021-09-08 09:35:58
【问题描述】:
想象一下,我正在使用 ngIf 来呈现(或创建)一个组件,并且我正在基于 ngIf(或 ngSwitch)的组件之间切换。无论模式问题如何(尽管我认为在组件之间切换时使用路由器是一种更好的模式),在性能方面,如果我使用路由器插座而不是 ngIf 块(反之亦然)会有任何性能提升吗?
可视化
使用 ngIf
<ng-container *ngIf="condition === a">
<a-component></a-component>
</ng-container>
<ng-container *ngIf="condition === b">
<b-component></b-component>
</ng-container>
使用路由器插座
<router-outlet></router-outlet>
【问题讨论】:
标签: angular