In my code, I am using a Factory with ng.resource:
.factory('company', function($resource){
return $resource(appHelper.apiPath('auth/company/info'), {}, {
update: {
method: "PUT"
}
});
});
When submitting the form in my Controller, everything functions correctly as long as the API gives a positive response. However, if there is an error, the API returns a JSON object with HTTP 200. In my callback function, I validate the response:
$scope.saveCompanyForm = function (company) {
company.$update(
function(data) {
if(data.status == 'ERROR') {
alert("error from API")
} else {
alert("no error")
}
}, function(error) {
alert("error")
}
The issue arises when the API returns an error and the form gets cleared. Strangely, if the API responds with HTTP 500 or 404, the form does not get cleared. Is there any way to prevent Angular from resetting the form? Thank you.