I need to select the instance of a html
element for its id
from the ts
of a page
of ionic
, how do I do this?
I need to select the instance of a html
element for its id
from the ts
of a page
of ionic
, how do I do this?
I would NOT use a selector by ID, I would use a selector by reference , but I'll leave you both in case you have your reasons to do it in one way or another :
BY ID:
document.getElementById('myID')
BY REF:
HTML:
<span #MyRef>Quiero este elemento a escoger</span>
TS:
import { ElementRef, ViewChild, ngAfterViewInit } from '@angular/core';
@ViewChild('MyRef') element: ElementRef;
ngAfterViewInit() {
console.log(this.element);
}