[英]If ng-content has content or empty Angular2
I am trying to understand how to create an if to show when a ng-content
is empty. 我试图了解如何在
ng-content
为空时创建if来显示。
<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>
I've tried to use that one to show a display data when the content is empty but even if the information is empty doesn't show the <span>
tag 当内容为空时我试图使用那个显示数据,但即使信息为空也不会显示
<span>
标签
Thanks, always grateful for your help. 谢谢,永远感谢你的帮助。
Use children
instead of childNodes
. 使用
children
而不是childNodes
。 Angular creates comment nodes for *ngIf* which are counted by
childNodes` Angular为
*ngIf* which are counted by
创建注释节点, *ngIf* which are counted by
childNodes` *ngIf* which are counted by
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.