Angular 2+ ngIf 没有阻止子组件的构建
Angular 2+ ngIf Not Stopping Child Component From Building
我有一个调用子组件的父组件。我想要一个 ngIf 检查 show/build 或 hide/don 不构建子组件...无论构建什么组件,即使未显示(不在 dom 中)。还有其他方法可以阻止这种情况发生吗?
父级 HTML 模板:
<div>
<child-comp *ngIf="1 == 0"></child-comp>
</div>
我在想 ngIf 不会带我去我想去的地方。
将您的 ngIf
支票放在 div
外 child-comp
周围
我有一个调用子组件的父组件。我想要一个 ngIf 检查 show/build 或 hide/don 不构建子组件...无论构建什么组件,即使未显示(不在 dom 中)。还有其他方法可以阻止这种情况发生吗?
父级 HTML 模板:
<div>
<child-comp *ngIf="1 == 0"></child-comp>
</div>
我在想 ngIf 不会带我去我想去的地方。
将您的 ngIf
支票放在 div
外 child-comp