Skip to content

Instantly share code, notes, and snippets.

@rexar1988
Created September 26, 2018 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexar1988/c38d79a5ec63cb586eeb908830394a39 to your computer and use it in GitHub Desktop.
Save rexar1988/c38d79a5ec63cb586eeb908830394a39 to your computer and use it in GitHub Desktop.
Angular 4: Get element from html to ts
@Component({
selector: 'sample',
template: `
<span #tref>I am span</span>
`
})
export class SampleComponent implements AfterViewInit {
@ViewChild("tref", {read: ElementRef}) tref: ElementRef;
ngAfterViewInit(): void {
// outputs `I am span`
console.log(this.tref.nativeElement.textContent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment