How to clear md-autocomplete cache?

I am using md-autocomplete to display api request results. The md-items attribute item in getItems(searchText) as promised: item in getItems(searchText) .

This works well, and using subsequent cache use of the same search text immediately returns the same results.

But I need to clear the cache at some points when other search options change. How can i do this? Perhaps access to the md-autocomplete controller? Although this seems non-standard, and I'm not sure how to do it.

+6
source share
3 answers

Starting with version 1.0.5 of the angular material, this is not possible. I did not find acceptable workarounds, so I just disabled the cache using md-no-cache="true" .

I recorded a problem for this in an angular project, including a suggestion on how it might work.

+6
source

It is definitely possible to reset the md-no-cache attribute programmatically at any time in your md-autocomplete .

If the controller has a boolean, let's say:

 $scope.noCacheResults = false; 

Then in your directive you can bind this variable to the md-no-cache attribute:

 <md-autocomplete ... md-no-cache="noCacheResults"> </md-autocomplete> 

As with every change to the search parameters, you can set $scope.noCacheResults to true or false depending on whether you want to keep caching query results or not.

+2
source

Something that worked for me. Put ng-if on your autocomplete. Then, in the code that changes the value of other fields affecting this field, set this value to false, and then set the value to true again during the timeout. This will effectively remove the element from the DOM and return to it everything beautiful and new without a cache.

0
source

All Articles