kadoshms/ionic2-autocomplete

Empty the value of searchbar from controller

Closed this issue · 7 comments

GREPY commented

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

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.

same question.

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

GREPY commented

Wonderful, thanks, now it works :) 👍

And what about capturing submit event?

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

Thank you, I put it inside the form :)

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