$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 made the function returns all elements of the set! This code looks for 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, that it does, but when I delete the string it is as a parameter it returns all elements that are in .json. The fact is that the page is paginated, organized from 8 to 8 elements, which are part of .json, when I delete the string that is as a parameter it returns all elements of json, it does not keep the pagination! I already tried to put a refresh when erasing but it went wrong! Thank you for your attention!