如何从ion-searchbar获取输入? [英] How to get input from ion-searchbar?
问题描述
这是一个超级容易的问题,但我似乎无法弄清楚(是的,我已经阅读了文档).
It is super easy problem but I just can't seem to figure this out (And yes I have read the documentation).
我试图让输入的用户在按搜索并放入const/let后放入ion-searchbar
(在Ionic v4中).
I am trying to get the input user puts in the ion-searchbar
(in Ionic v4) after they the press search and put in a const/let.
Mah HTML
<ion-searchbar showCancelButton="focus" class=""></ion-searchbar>
我不知道该怎么写TS.
I don't know how I should write the TS for this.
预先感谢: {)
推荐答案
-
使用(搜索)事件来调用您的函数.当用户单击ion-searchbar提供的搜索按钮时,将触发此事件.
Use (search) event to call your function. This event is fired when the user will click on the search button provided by the ion-searchbar.
要获取在搜索栏中输入的值,请使用 $ event.target.value ,它获取标记的value字段,在本例中为
'<ion-searchbar>'
To get the value entered in the searchbar, use $event.target.value which gets the value field of the tag which in this case is
'<ion-searchbar>'
'
<ion-searchbar showCancelButton searchIcon="search" animated cancel-button-icon (ionCancel)="hideSearch()" (search)="yourSearchFunction($event.target.value)" placeholder="Search Some Values" ></ion-searchbar>
'这篇关于如何从ion-searchbar获取输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!