【发布时间】:2020-11-07 18:59:37
【问题描述】:
我有一个组件<my-component>,我只想在设置了它的一个属性时才显示它。所以我想在<my-component>做这样的事情:
<ng-container *ngIf="myProperty">
<div>...</div>
</ng-container>
组件是在 HTML DOM 中创建的。因此,为了避免它的创建,我的假设是我应该将 *ngIf 放在 <my-component> 的选择器上 <parent-component> 中,这将是这样的:
<parent-component>
<my-component *ngIf="myProperty"></my-component>
</parent-component>
但在这种情况下,属性 myProperty 将设置在 <my-component> 而不是 <parent-component>。
那么,如果我的假设是正确的,那么实现它的方法是什么?
【问题讨论】:
标签: javascript angular angular-ng-if