1 回答
TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
因此,這是 的預(yù)期行為ng-content,要么您將[select]指向某個(gè)ng-content,要么您可以僅在第一次出現(xiàn) 時(shí)進(jìn)行渲染ng-content。
我嘗試了一種對(duì)我有用的方法。這是演示工作代碼
<any-selector>
<div #myProjection>content to place</div>
</any-selector>
然后在app-selector.HTML中你可以這樣做:
<div id='border'>
<h1>Hello Component</h1>
<header><div #canvas></div></header>
<footer><div #canvas></div></footer>
</div>
應(yīng)用程序選擇器.組件
@ViewChildren("canvas") canvas: QueryList<ElementRef>;
@ContentChild("myProjection") str : ElementRef;
ngAfterViewInit() {
this.canvas.forEach((div: ElementRef) =>
div.nativeElement.insertAdjacentHTML('beforeend', this.str.nativeElement.innerHTML));
}
- 1 回答
- 0 關(guān)注
- 141 瀏覽
添加回答
舉報(bào)
