Wrap ng-content
in an HTML element like a div
to get a local reference to it, then bind the ngIf
expression to ref.children.length == 0
:(将ng-content
包裹在div
类的HTML元素中以获取对其的本地引用,然后将ngIf
表达式绑定到ref.children.length == 0
:)
template: `<div #ref><ng-content></ng-content></div>
<span *ngIf="ref.nativeElement.childNodes.length == 0">
Display this if ng-content is empty!
</span>`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…