【发布时间】:2017-01-12 23:03:43
【问题描述】:
我想通过访问ng-content 标记之一(最好是通过其select 属性)来查询我的模板中的嵌入内容,而无需在元素上设置局部变量。
这可能吗?
<comp>
<span world>Hello world</span>
</comp>
模板:
<div>
<ng-content select="[world]"></ng-content>
</div>
Comp.ts:
@ContentChild('world') world: ElementRef;
上述方法不起作用,这是意料之中的,因为我只是从臀部射击。
如何查询 ng-content 的内容?
用例是检查内容是否已经真正传递给组件。
【问题讨论】:
标签: angular