1
Hi, I am have a function that searches in a list the occurrence of some string typed in the field that is passed as its parameter, it works well to fetch these strings:
$scope.$watch('q', function(newValue, oldValue) {
if (oldValue != null){
$http.get('/api/services.json?q=' + newValue)
.success(function (data) {
$scope.services = data;});
}
}, true);
}]);
The problem that is presented is that when I delete any character from the search I did the function returns all the elements of the set! This code is that searches what was done in the function.
<div class="search">
<input type="text" placeholder="Buscar por serviços" ng-model="q">
</div>
<div class="banner">
<div class="search">
<input type="text" placeholder="Buscar por serviços" ng-model="q">
</div>
<h2 class="title" style="color: #A2121F;">Serviços em destaque
</h2>
</div>
<h3 ng-if="services.length == 0">Nenhum serviço encontrado.</h3>
<div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 200 }'>
<div class="col-6 services_card" ng-repeat="service in services" ng-if="service.active == true">
<a class="section" href="{{ service.url }}">
<h3 class="title" >{{service.name}}</h3>
</a>
</div>
</div>
In this line $http.get('/api/services.json?q=' + newValue) is to return the occurrences, in a json file, of the string, it does, but when I delete the string that is as parameter it returns all the elements that are in .json. The fact is that the page is paged, organized of 8 in 8 elements, which are part of the . json, when I delete the string that is as parameter it returns all elements of json, it does not keep pagination! I tried to put a refresh when I was blacking out but it went wrong! Grateful for the attention!
Please, if possible, include a example of code that reproduces what is happening, because your question is not perceptible. See Help Center How to Ask.
– Sorack
edited the statement
– Carlos Andre
Do you just want to filter your current list or filter the total list? If you are a filter from the current list, use "| filter: { name: q }" in ng-repeat and remove $watch
– MarioAleo