I'm new to Angular and I'm using some of the features to post data to a endpoint - a endpoint that I have complete control over. Its a very simple endpoint with CRUD capability allowing me to work with "customer" entities for educational purposes.
I have a partial view that basically lists all the customer. On each row, there is a delete button that allows me to delete that customer. When deleting a customer a request is sent to the endpoint. The endpoint will then check if a customer is "admin", if so, return a JSON response which says "You cannot delete a admin", otherwise, delete the customer and send back "Customer deleted" JSON response.
Upon receiving a response from the server, the angular application should do logic depending on the response data. The endpoint is working as intended. However, I'm getting some strange/unexpected result.
Here is what my code looks like:
In a" SecretsController", I have the following:
$scope.deleteUser = function (userName, $event) {
credentialsService.removeRegistredUser(userName).then(function (response) {
if (response.data.Feedback === "Error") {
$rootScope.currentStatus = "There was a error raised: " + response.data.Message;
} else {
$rootScope.currentStatus = "User sucessfully removed.";
var currentRow = $event.target.closest("tr");
$(currentRow).fadeOut(1500, function () {
currentRow.remove();
});
};
fireResponseToGui();
}, function (error) {
$rootScope.currentStatus = "Invalid request: " + error.status + ". The response is: " + error.statusText;
fireResponseToGui();
});
};
And in :
var deffered = $q.defer();
var credentialsServiceFactory = {};
credentialsServiceFactory.removeRegistredUser = function (userMail) {
$http.post(registratedUsersEndpoint + apiDelete + userMail + "&token=" + token)
.then(function (response) {
deffered.resolve(response);
}, function (error) {
deffered.reject(error);
});
return deffered.promise;
};
And there is the problem. After some checking with console.log(), the "return deffered.promise" line in the service seems to return the exact same result although the response object in the service is different. Anyone now what I'm doing wrong here?