How to select an html element for the id from the ts with Ionic?

0

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?

    
asked by Daniel Enrique Rodriguez Caste 16.08.2017 в 23:09
source

1 answer

2

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);
}
    
answered by 18.08.2017 / 13:28
source