In my factory I have this function which calls a delete api as following :
removeOffre: function(id) {
return $http.delete('http://localhost:8080/removeOffre/'+id)
.then(function(response) {
return response;
}, function(error) {
return 'There was an error getting data';
});
},
this function works.
and then I want to delete multiple entries so I use this function for that :
removeSelectedItems: function(selectedItems) {
let deleted = true;
angular.forEach(selectedItems,function(id){
$http.delete('http://localhost:8080/removeOffre/'+id)
.then(function(response) {}, function() {
deleted = false;
});
});
return response;
}
in the server side all entries are deleted, but in my browser console I get this error :
Error: response is not defined
factory.removeSelectedItems@http://localhost:9000/scripts/providers/offresFactory.js:60:7
deleteSelectedItems/$scope.ok@http://localhost:9000/scripts/controllers/offreController.js:135:5
anonymous/fn@http://localhost:9000/scripts/js/angular.min.js line 212 > Function:2:194
I call this function from my controller as following :
offresFactory.removeSelectedItems(entriesToDelete).then(function (state) {
if(state == true) $state.go($state.current, {}, {reload: true});
}, function (error) {
console.log(error);
});
How can I solve this ?
responsein methodremoveSelectedItemsbut you never define a variable namedresponse.