I want to make online search in angularjs, using ng-keyup function. But I suppose that it is wrong to make query to BD on each keyup. So how can I set timer that will make $http service work only if in last 3 second there were no keyups?
<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);
}
);
};
});