Here is the function I have created:
$scope.saveManualResendDraft = function(todo) {
if ($scope.editMode) {
updateStartJobManual();
byeSendManualInputDirectly();
} else {
console.log('bye');
}
};
I have defined two functions called updateStartJobManual() and byeSendManualInputDirectly().
I want to ensure that the first function completes fully before moving on to the second. Is it possible to achieve this using promises? Can someone provide me with a sample code snippet?
function byeSendManualInputDirectly() {
if ($window.confirm("Do you want to send this message?"))
addProfSms();
else
console.log('no');
}
function addProfSms() {
$http.post('/api/sendprofsms', $scope.draft).then(function(response) {
swal("Good job!", "Message sent!", "success")
// $state.reload();
});
}
function updateStartJobManual() {
$http({
method: 'POST',
url: '/api/updatestartjobmanual',
data: $scope.draft
}).then(function(response) {
$scope.currentItem = response.data;
$scope.todos[$scope.currentItemIndex] = response.data;
$scope.editMode = false;
console.log('draft:', response.data);
$state.reload();
// toastr.success('Updated Successfully');
}, function(response) {
console.log('error');
});
}