Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically clear a material design autocomplete in angularjs?

I have a material design autocomplete working correctly. Now I need to be able to clear the selected element when a button is clicked. I see that the element's delete button that appears on the right has an $mdAutocomplete.clear() call which is exactly what I need but I don't know how to launch that.

How can I capture the element and call the clear() method? Thanks

like image 727
tsolucio Avatar asked Feb 11 '26 05:02

tsolucio


1 Answers

Try to set the model which is binded to the search text with empty string:

self.clear = function() {
  self.searchText = '';
}

See this codepen

like image 199
eladcon Avatar answered Feb 13 '26 19:02

eladcon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!