Skip to content

Instantly share code, notes, and snippets.

@guillefd
Created February 7, 2018 22:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillefd/8049b318143c37aa386a148c14bd8d21 to your computer and use it in GitHub Desktop.
Save guillefd/8049b318143c37aa386a148c14bd8d21 to your computer and use it in GitHub Desktop.
Angular, get HTML Element by ID
import { Component, OnInit, EventEmitter, Output, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'form-place',
template: `<div #gmap>You got me!</div>`,
styleUrls: ['./form-place.component.scss']
})
export class elementComponent implements OnInit {
@ViewChild("gmap", {read: ElementRef}) gmap: ElementRef;
constructor(private elementRef: ElementRef) {}
ngAfterViewInit(): void {
console.log(this.gmap.nativeElement);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment