Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 687 Bytes

elementref.md

File metadata and controls

35 lines (26 loc) · 687 Bytes

ElementRef

Provides access to the underlying native element (DOM node).

import {Component, ElementRef} from '@angular/core';

@Component({
	selector: 'app',
	template: `
  <h1>My App</h1>
  <pre style="background: #eee; padding: 1rem; border-radius: 3px; overflow: auto;">
    <code>{{ node }}</code>
  </pre>
`
})
export class App {
  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;
  }

}

View Example