DEV Community

loading...

Discussion on: Angular: Build more dynamic components with ngTemplateOutlet 🎭

Collapse
avoerman profile image
Alex Voerman

Maybe worth mentioning since it's a relatively undocumented feature, but the slotting feature that comes with the transculsion api could be helpful for the 2nd scenario:

<app-card [title]="title">
  <h2 title>Hello there</h2>
  <p>i'm an awesome card.</p>
</app-card>

<div class="card">
  <header [select]="title"></header>
  <article>
    <ng-content></ng-content>
  </article>
</div>

Although it doesn't cover the union-type check in your example.

Collapse
mustapha profile image
Mustapha Aouas Author

Yes, the slotting feature is great an could help a lot depending on the scenario. When it comes to overloading templates and building reusable components i find the code to be easier to maintain with templateOutlet, but that’s only my two cents.

Thanks for sharing πŸ˜ƒ