I am encountering an issue with the code snippet below. The control does not wait for the HTTP promise to be resolved before returning a string from the method, and I can see that the returned object is "method" in the switch statement. Can someone please help me figure out what mistake I have made here?
The controller contains the following logic:
var status = function(action) {
switch(action) {
case 'create':
return $scope.submitdata();
break;
default: alert();
}
}
$scope.submitdata = function() {
service.postdata($scope.formdata)
.success(function(data) {
$scope.response = data;
return 'SUCCESS';
})
.error(function(error) {
Console.log(error);
return 'FAILURE';
})
}
Service Method:
this.postdata = function(data) {
return $http.post(URL, DATA);
}