tigrenok00
tigrenok00

Reputation: 155

How to get the last key pressed in nativescript SearchBar?

I want to know what is the last keystroke in SeachBar (and check whether it is a backspace specifically).

Can it be done using searchBarTextChanged(args) event?

I'm using Angular and looking for a solution for both Android and iOS.

Thanks!

Upvotes: 0

Views: 415

Answers (1)

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

I'm using <SearchBar (textChange)="search(searchBar.text)"> in the view, and something like this in the component:

search(term?: string): void {
  // reduce your list based on the search term
}

I'm not detecting the backspace as I'm always reducing the list (that the search term is applied to) based on the input. So if previously a term has been entered and backspace was pressed, the term would now be '' which means the entire list can be shown.

Upvotes: 1

Related Questions