<elementRef>
import {ElementRef} from "@angular/core";
constructor(private element: ElementRef) { // now, we can reference to: this.element}
this.element.nativeElement('.js-banner-container'),
Provides access to the underlying native element (DOM element).
import {AfterContentInit, Component, ElementRef} from '@angular/core';@Component({ selector: 'app', template: `My App
` }) export class App implements AfterContentInit { node: string; constructor(private elementRef: ElementRef) { } ngAfterContentInit() { const tmp = document.createElement('div'); const el = this.elementRef.nativeElement.cloneNode(true); tmp.appendChild(el); this.node = tmp.innerHTML; } }{ { node }}
参考这篇