Angular DOM

Rendering what's displayed inside the DOM, using control flow and directives.

Published: 2/17/2021

Note: Since v17 there’s an $@$ syntax that doesn’t require the ‘CommonModule’ to be imported.

ng-container is a special element that can hold structural directives (ngIf, ngFor) without adding new elements to the DOM.

Code:


<section>
  <ng-container>
    <h3>User bio</h3>
    <p>Here's some info about the user</p>
  </ng-container>
</section>

Render:

<section>
  <h3>User bio</h3>
  <p>Here's some info about the user</p>
</section>

Rendering a components wrapper such as <app-my-component> can interrupt nesting requirements, especially in flex box frameworks where .row > .col etc.

Add this to the components css: :host { display:contents }