I have a component <my-component>
that I want to only show if one of its properties is set. So I thought about doing something like this in <my-component>
:
<ng-container *ngIf="myProperty">
<div>...</div>
</ng-container>
The thing is the component is created in the HTML DOM. So, to avoid its creation, my assumption is that I should put the *ngIf on the selector of <my-component>
in <parent-component>
, which would make something like:
<parent-component>
<my-component *ngIf="myProperty"></my-component>
</parent-component>
But in this case, the property myProperty would be set in <my-component>
and not in <parent-component>
.
So, if my assumption is correct, what is the way to implement that?