Iam trying to build a auto search In angularjs. Iam able to get values in Json obj and loop through the list based on search., but when I give 'backspace' or delete the text and try to enter again., Old search results is appending to auto suggests. I dont get how to remove it from array. Please pind plunker below for code.
code problematic section below.Here Iam getting different search results than which I supposed to get
for (var i=0 ; i < $scope.suggestionResults.length ; i++){
//if($scope.suggestionResults[i].title.indexOf(suggestText) > -1)
//if($scope.suggestionResults[i].title.match(suggestText))
var str = $scope.suggestionResults[i].title;
if(str.indexOf(suggestText) > 0)
//$scope.suggestionResults[i].title.match(suggestText)
{
output.push($scope.suggestionResults[i].title);
} else{
console.log(suggestText + 'Not matching');
//array.splice(index, 1);
if(output.length > 0){
output[i].splice($scope.suggestionResults[i].title, 1);
}
}
$scope.filterSearch = output;
console.log($scope.filterSearch);
// if ($scope.suggestionResults[i].title.includes(suggestText)) {
// output.push(suggestText);
// }
// $scope.filterSearch = output;
}




loadash, it is easy to use<li class="list-group-item" ng-repeat="values in suggestionResults | filter:searchText" ng-click="showProduct(searchText)">{{values.title}}</li>