简体   繁体   English

点击取消按钮时删除/关闭 Angular 或 Ionic 5 中的搜索栏

[英]Remove/Close search bar in Angular or Ionic 5 when hitting cancel button

I am using Ionic on mobile and I want to make sure that when you hit the cancel button, the search bar is removed totally .我在移动设备上使用Ionic ,我想确保当您点击取消按钮时,搜索栏会完全删除 Even better: when you hit any area outside the search bar.更好的是:当您点击搜索栏外的任何区域时。 I am already showing the search bar after a click on an icon.单击图标后,我已经显示了搜索栏。

   <ion-searchbar
            *ngIf="toggled"
            placeholder="Search"
            inputmode="text" type="text"
            [(ngModel)]="searchTerm" mode="ios"
            (ionChange)="onSearchChange($event)"
            (ionCancel)="showDefaultBar()"
            (ionBlur)="showDefaultBar()"
            showCancelButton="always"
            [debounce]="250"
            animated="true">
</ion-searchbar

Here is the code.这是代码。 So, you can see that the cancel button is always being shown.因此,您可以看到始终显示取消按钮。 The problem is that when you hit cancel, it only clears the text input field and does not actually cancel the searchbar.问题是当你点击取消时,它只会清除文本输入字段,并不会真正取消搜索栏。 I would like to make sure the searchbar is hidden/removed after hitting cancel, like on native iOS .我想确保在点击取消后隐藏/删除搜索栏,就像在原生iOS上一样。

Is there a way to do this?有没有办法做到这一点? Couldn't find anything in the Ionic documents.在 Ionic 文档中找不到任何内容。

In the.ts file, you can do this in the showDefaultBar() function:在 .ts 文件中,您可以在showDefaultBar() function 中执行此操作:

showDefaultBar() {
  this.toggled = false;  <-- add this line
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM