I am really new to angular so this may be super simple but I can't seem to get it to work. I have an app that has a search field that needs to actively filter the results as a user types. All of my data is in the searchResults object. Nothing happens when I type in the textbox. What am I missing? Thanks in advance for your help.
<div>
<input ng-model="query" name="search" id="search" type="text" placeholder="search by product or category">
<ul id="filteredResults" ng-if="results.length">
<li ng-repeat="result in results | filteredSearchFilter | limitTo: 10">{{result.name}}</li>
</ul>
</div>
filteredSearch.filter.js
module.exports = function() {
return function(data, keys, query) {
results = [];
if( !query ){
return data;
} else {
angular.forEach( data, function( obj ){
var matched = false;
angular.forEach( keys, function( key ){
if( obj[key] ){
// match values using angular's built-in filter
if ($filter('filter')([obj[key]], query).length > 0){
// don't add objects to results twice if multiple
// keys have values that match query
if( !matched ) {
results.push(obj);
}
matched = true;
}
}
});
});
}
return results;
};