Ionic get value?

Hi, friends

   let e = document.getElementById('idElement');
   let val = e.nodeValue;

help in this

Hi, you can do the following ways:

  1. In you HTML
<ion-input #idElement>

In your TS

set before your constructor

@ViewChild('idElement') elem: ElementRef;

then in your function

let val = this.elem.nativeElement.value
  1. alternatively, you can use NgModel which is faster and easy, which works like this
<ion-input [(ngModel)]="idElement">

then above your constructor

idElement:string = ''

then in your function


ngModel is a two way binding which is easy to work with