0

How do I retrieve an ion-input value in Ionic 2?

In my example.html I have this:

<ion-input value="hello" type="text" id="ion1"></ion-input>

While in example.ts I tried in this way, following this (maybe outdated) question:

let inputValue = (<HTMLInputElement>document.getElementById("ion1")).value;

But I get undefined in google chrome console.

Community
  • 1
  • 1
splunk
  • 6,435
  • 17
  • 58
  • 105

1 Answers1

1

You can enable two way binding over your ion-input by doing adding [(ngModel)]

<ion-input>
  <ion-label>Enter text...</ion-label>
  <input type="text" [(ngModel)]="searchInput" />
</ion-input>

Then inside Component class you could specify value for searchInput property.


Other way would be

<ion-input type="text" [(ngModel)]="searchInput"></ion-input>
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299