When I click a button in my AngularJS app, the following code is executed:
if (!$scope.isChecked) {
$scope.getExistingName($scope.userName).then(function (data) {
$scope.userName = data;
});
}
// Additional processing code followed by another promise
myService.save($scope.userName,otherparams).then(function (res) {
// Redirect to a different page
}, function (err) {
});
The problem arises when $scope.isChecked is false, as it enters the promise and before resolving, moves on to the next line of code. This results in $scope.userName not being updated with the new value returned.
I'm seeking suggestions for the best approach to handle this situation. Any advice?