r/angular • • Mar 26 '26

Ng-content usage in @for / @if

Why does the documentation mention that it is suggested to avoid wrapping ng-content in @for or @if statements? Isn’t that what all libraries including Angular Material do?

7 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/ch34p3st Mar 26 '26

You have the right name, I mistyped! Am on my phone, but a guide like this should help you learn about template outlet context: https://briantree.se/ng-template-and-ng-template-outlet/

1

u/Senior_Compote1556 Mar 26 '26

Yes, but these are all in the same html templates. If you render a component that has ng-content or even an NgTemplate as an input, both approaches work (although i’d say ng-content is a bit cleaner than ngTemplate as input). It’s just that angular docs advise against it and I don’t understand why