I want to filter according to what the user types on the screen. I have a form with ng-model="q"
and | filter:q
Where my http.get step is the parameters I'm filtering, where ng-model is the "find:
$scope.pagination = {
limit: 10,
offset: 0
};
$scope.pagination.limit = 8;
$scope.pagination.offset = 0;
$scope.q = '';
$scope.noMoreItemsAvailable = false;
$scope.ofertass = [];
$scope.getRecord = function () {
$http.get("http://meusite.com.br/admin/apis/api_listagem/lista_oferta_api.php?json=promocao" + "&latitude=" + $scope.lat_cliente + "&longitude=" + $scope.long_cliente + "&raio=" + $scope.raio + "&limit=" + $scope.pagination.limit + "&offset=" + $scope.pagination.offset + "&busca=" + $scope.q).then(function (response) {
// console.log(response.data);
if (response.data.length) {
$scope.ofertass.push.apply($scope.ofertass, response.data);
$scope.pagination.offset = $scope.pagination.offset + $scope.pagination.limit;
window.localStorage.setItem("data_ofertass", JSON.stringify(response.data));
} else {
$scope.noMoreItemsAvailable = true;
if (window.localStorage.getItem("data_ofertass") === null) {
$state.go("nhaac.nachegamos");
}
}
},
function (response) {
// error message
var alertPopup = $ionicPopup.alert({
title: "error " + response.status,
template: response.statusText + "<br/>Problema: Conexão com sua Internet.",
});
}).finally(function () {
console.log("finally....");
$scope.$broadcast('scroll.infiniteScrollComplete');
});
}
$scope.doRefresh = function () {
limit = 20;
offset = 0;
$scope.q = '';
$scope.noMoreItemsAvailable = false;
$scope.getRecord();
};
It works fine, but when I empty the search field it returns blank results with the last filter down.
Follow my search in View:
<center>
<form ng-submit="fechaTeclado()">
<div class="bar bar-subheader bar-light">
<label class="item item-input item-floating-label">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" size="100" ng-model="q" placeholder="Procurar" type="submit" ng-submit="fechaTeclado()" ng-click="fechaTeclado()" />
<input type="submit" id="submit" value="OK" ng-click="fechaTeclado()" />
</label>
</div>
</form>
</center>
What am I doing wrong? I test the URL with the parameters and it works fine ...
If I leave "& search=" empty I list everything. This is correct. But in my application, it is not cleaning up the search.
EDIT:
You have the KeyDate () function that is just to close the device keyboard:
$scope.fechaTeclado = function (q) {
$cordovaKeyboard.close();
$scope.q = q;
$scope.getRecord();
};
I think of using a slice () or splice () in getRecord, to eliminate what it should not look like:
Notice in the image above that there are white spaces that were filled before the filter, and if drag shows what was searched.
But I'm on a good logic how to do this.