Angular material autocomplete search anywhere in string?

This is a function from the original md-autocomplete:

function createFilterFor(query) {
  var lowercaseQuery = angular.lowercase(query);
  return function filterFn(state) {
    return (state.value.indexOf(lowercaseQuery) === 0);
  };
}

Please try changing the condition a little bit, like this:

    return (state.value.indexOf(lowercaseQuery) >= 0);

and it should work the way you want.


The demo only matches characters at the beginning of the result due to specifying the caret flag, ie: md-highlight-flags="^i"

To allow autocomplete to find any matching characters you should use the global flag, ie: md-highlight-flags="gi"

You will also need to change the state.value.indexOf(lowercaseQuery) === 0 line in the filterFn function to state.value.indexOf(lowercaseQuery) !== -1

Check this codepen for a working example: http://codepen.io/DevVersion/pen/KrOYoG