kadoshms / ionic2-autocomplete

Ionic 2 autocomplete component
MIT License
149 stars 108 forks source link

Empty the value of searchbar from controller #135

Closed GREPY closed 6 years ago

GREPY commented 6 years ago

Hello, I'm new to Angular and I need help with this module. I need to erase the string inside autocomplete component after item is selected, or space/enter key pressed. I use events itemSelected when item is selected and ionAutoInput when space is pressed - but it is not fired on enter key. I have 2 questions:

  1. How can I bind event to enter key press when focused to autocomplete component?

  2. How can I erase (make it empty) string inside autocomplete component from my controller?

Thanks!

GREPY commented 6 years ago

Will you help me, please? I assigned the model with ngModel but two way data binding is not working when I erase the model in controller. And by "enter key press" event I meant tapping search (confirm) button on mobile keyboard. Thank you.

ar27111994 commented 6 years ago

same question.

ar27111994 commented 6 years ago

ok got the solution: Component Mapping to Controller @ViewChild('nameFilter')nameFilter: AutoCompleteComponent; Controller method code this.nameFilter.clearValue();

GREPY commented 6 years ago

Wonderful, thanks, now it works :) :+1:

And what about capturing submit event?

ar27111994 commented 6 years ago

I'm glad it worked for you. Input fields don't have submit events, forms and buttons have it. You can use nameFilter.getValue() inside your submit() function to get the selected value in AutoCompleteComponent .

GREPY commented 6 years ago

Thank you, I put it inside the form :)

JeongJun-Lee commented 6 years ago

But I think it's still bug. The two-way binding by NgModel should work well.