Home > Blockchain >  What happens to empty ng-content fields
What happens to empty ng-content fields

Time:09-16

Simple question:

The Angular docs suggest not using ng-content in the case of conditional rendering on the component end:

If your component needs to conditionally render content, or render content multiple times, you should configure that component to accept an element that contains the content you want to conditionally render.

Using an element in these cases is not recommended, because when the consumer of a component supplies the content, that content is always initialized, even if the component does not define an element or if that element is inside of an ngIf statement. From: enter image description here

You can try to change the ngIf to true to see how it appears in the DOM (and the custom directive gets initialized as well, which won't if the ngIf is false)

  • Related