Hi I want to cancel my http request after 2s. If no data was received it should resolve into the error function and return an empty object.
I know I somehow have to use the timeout property. Where do I use the $timeout exactly? I am not so sure if I understood it correctly.
app
.service('testService',['$http','$q','$timeout',
function($http,$q,$timeout){
var canceler=$q.defer();
this.options = function (long,lat) {
return $http({
method: 'POST',
url: '/coordinates',
headers: {
'Content-Type' : 'application/json; charset=utf-8',
'Data-Type': 'json'
},
data: {
"long":long,
"lat": lat
},
timeout:canceler.promise
}).then(function (response) {
return response.data;
},function(error){
return {};
});
};
}]);