Ion 2 ion-search panel ionClear does not work when a button is pressed

I have a search bar 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 the function in the corresponding TS file:

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

But the 'onClear' event never fires when search bars are clicked with a small click on x. Why is this?

+4
source share
3 answers

After @ Ivario18 suggested changing the transparency to (ionCancel), I added (ionCancel) as well as (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 kernel is working ...

+1
source

Change it to (ionCancel)Maybe you are using an obsolete ionic conductor.

+3
source

, (ionCancel), [showCancelButton] = "true". , (ionClear), , .

0
source

Source: https://habr.com/ru/post/1658299/


All Articles