With callbacks, I wrap the callback in an Angular $timeout block so that it updates the UI.
function makeServerRequest(callback) {
$timeout(callback);
}
makeServerRequest((response) => {
$scope.updateUI();
})
This operates within the Angular digest cycle, and the UI gets updated.
However, this doesn't work:
function makeServerRequest() {
return new Promise((resolve, reject) => {
$timeout(() => {
resolve();
});
})
}
makeServerRequest().then(() => {
$scope.updateUI();
})
In this case, it seems like the resolve happens, and then $scope.updateUI();
is called after the timeout.
How can I wrap resolve
inside a timeout, so that the outside .then is called inside a timeout?