Ionic get value?

Hi, friends

  add(d)
 {
  
   let e = document.getElementById('idElement');
   let val = e.nodeValue;
   alert(val);
 }

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
alert(val)
  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

alert(idElement)

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