如何在angular 2/typescript中附加html内容

如何在angular 2/typescript中附加html内容,angular,typescript,angular5,angular2-template,Angular,Typescript,Angular5,Angular2 Template,我想使用insertAdjacentHTML将HTML内容附加到一个div(“单窗格”)中,但什么也没发生。不知道我在这里错过了什么 这是我试图附加的HTML内容---> component.html 如果只有一个通知类型的元素,请使用ViewChild而不是ViewChildren。 并将其声明为ElementRef类型 export class SiteNotificationComponent implements OnInit { @ViewChild('notification'

我想使用insertAdjacentHTML将HTML内容附加到一个div(“单窗格”)中,但什么也没发生。不知道我在这里错过了什么

这是我试图附加的HTML内容---> component.html


如果只有一个通知类型的元素,请使用ViewChild而不是ViewChildren。 并将其声明为ElementRef类型

export class SiteNotificationComponent implements OnInit {
  @ViewChild('notification') el:ElementRef;
  parentClass: any;

  constructor() {}
  ngOnInit() {} 

  ngAfterViewInit() {
    this.parentClass = document.getElementsByClassName('single-pane')[0];
    this.parentClass.insertAdjacentHTML('afterbegin', this.notificationsElements.nativeElement.innerHTML);
  }
}

我尝试了您所建议的,它附加了[object HtmlLevel]试试这个。notificationsElements.nativeElement.innerHTML。我已经更新了答案。