Angular ng-content with default content
< 1 min read
When I faced the problem of setting a default content, my first thought was to put the content inside the
<ng-content> tags, but that didn't work. You will not find this in the Angular docs, but there is a workaround.
<div class="header">...</div> <div #contentRef class="content"> <ng-content></ng-content> </div> <div *ngIf="contentRef.childNodes.length === 0" class="content"> default content </div> <div class="footer">...</div>