Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic: Clear text field on page load

i have a text field in my html page as below :

<ion-input type="text"   (input)="getid($event.target.value)" autofocus="true" id="get_ticket_id"></ion-input>

i want this text field to be sent to blank/empty every time page loads/ user comes to the page by opening application or using back-button

how can i achieve that, i have done lot of search on this but could not find the solution, can someone please advise me how can it be acheieved

like image 825
stackoverflow account Avatar asked Mar 12 '26 02:03

stackoverflow account


1 Answers

Use ngModel, that is one of absolute essentials you should learn about Angular. Also together with ionViewWillEnter() as suggested. So something like this:

ts:

myInput = "";

ionViewWillEnter() {
  this.myInput = "";
}

getId(val) {
  console.log(val)
}

And the template:

<ion-input [ngModel]="myInput" (ngModelChange)="getId($event)"></ion-input>

So I also suggest to use ngModelChange instead of (input), we are coding with angular :)

like image 63
AT82 Avatar answered Mar 14 '26 21:03

AT82