如果 ng-content 有内容或为空 Angular2

If ng-content has content or empty Angular2

我正在尝试了解如何创建 if 以在 ng-content 为空时显示。

<div #contentWrapper [hidden]="isOpen">
    <ng-content ></ng-content>
</div>

<span *ngIf="contentWrapper.childNodes.length == 0">
    <p>Display this if ng-content is empty!</p>
</span>

我试过在内容为空时使用那个来显示显示数据,但即使信息为空也不显示 <span> 标签

谢谢,一直感谢您的帮助。

使用 children 而不是 childNodes。 Angular 为 *ngIf* which are counted bychildNodes`

创建注释节点
<div #contentWrapper [hidden]="isOpen">
    <ng-content ></ng-content>
</div>

<span *ngIf="contentWrapper.children.length == 0">
    <p>Display this if ng-content is empty!</p>
</span>  

Plunker example