Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 ion-Searchbar ionClear not firing on button click

I have a searchbar in my toolbar as follows:

  <ion-toolbar color="clarity">
    <ion-searchbar
      [(ngModel)]="searchText"
      [showCancelButton]="false"
      (ionInput)="onInput($event)"
      (ionClear)="onClear($event)">
    </ion-searchbar>
  </ion-toolbar>   

and a function in the corresponding TS file:

   onClear(event){
     this.searchText = "";
   }

But the 'onClear' event never gets hit when the searchbars little 'x' is clicked.. why is that?

like image 786
alsco77 Avatar asked Oct 20 '16 08:10

alsco77


2 Answers

Change it to (ionCancel) You're probably using an outdated ionic guide

like image 174
Ivar Reukers Avatar answered Sep 28 '22 06:09

Ivar Reukers


After @Ivario18 suggested I change the clear to (ionCancel), I added the (ionCancel) as well as the (ionClear):

<ion-toolbar color="clarity">
  <ion-searchbar
    [(ngModel)]="searchText"
    [showCancelButton]="false"
    (ionInput)="onInput($event)"
    (ionClear)="onClear($event)"
    (ionCancel)="onCancel($event)">
  </ion-searchbar>
</ion-toolbar>   

Now the clear is working...

like image 38
alsco77 Avatar answered Sep 28 '22 06:09

alsco77