【发布时间】:2020-10-22 12:35:06
【问题描述】:
我想将新的子节点 after 添加到父节点,但 appendChild 将其添加到 inside。这是我所拥有的:
我的component.html:
<div id="parent" (click)="appendChild()">
parent node
</div>
我的component.ts:
private appendChild() {
const div = this.renderer.createElement('div');
const text = this.renderer.createText('child node')
this.renderer.appendChild(div, text);
this.renderer.appendChild(document.getElementById("parent"), div)
}
这会插入在parent 节点内部创建的新div,如下所示:
【问题讨论】:
标签: angular typescript angular-renderer2