I want to do an online search in angularjs using the ng-keyup function. But I suppose it's wrong to query BD for each keyboard. So, how can I set a timer that will make the $ http service work only if there are no keys in the last 3 seconds?
<input type="text" ng-keyup="search(param.values, param.url)">
JS:
app.controller('searchCtrl', function($scope,$rootScope,$http){
$scope.search = function( values , type) {
var data={};
data.values=values;
data.type=type;
console.log(data);
$http.post("search.php", data).then(function success (response) {
console.log(response.data);
$rootScope.search_result=response.data;
},function error (response){
console.log(response.data);
}
);
};
});
source
share