【发布时间】:2018-06-13 05:32:45
【问题描述】:
我想使用 insertAdjacentHTML 将 HTML 内容附加到 div('single-pane') 中,但没有任何反应。不确定我在这里缺少什么。
这是我试图附加的 HTML 内容---> component.html
<div #notification class="notification-top-bar" style="display: block;">
</div>
这是我要附加的打字稿代码---> component.ts
export class SiteNotificationComponent implements OnInit {
@ViewChildren('notification') private notificationsElements: QueryList<ElementRef>;
parentClass: any;
constructor() {}
ngOnInit() {}
ngAfterViewInit() {
this.parentClass = document.getElementsByClassName('single-pane')[0];
this.parentClass.insertAdjacentHTML('afterbegin', 'notificationsElements');
}
}
【问题讨论】:
标签: angular typescript angular5 angular2-template