I am using ng-content to wrap one Angular component in another. The outer component should have full control about when the inner component is rendered or not. However, I ran into a situation, that I don't understand. The outer component uses a template like the following (simplified):
<ng-template>
<ng-content></ng-content>
</ng-template>
From my understanding, the content should not be rendered at all, as it is contained in the ng-template. In this example stackblitz, you can see that the inner component is not rendered, but it is still initialized. The console log in the inner component's OnInit still shows up in the console.
My question is:
- Why does this happen?
- How can I avoid component initialization in this case?