The problem I am experiencing is a bit hard to explain, and I might getting (Angular) promises wrong, but still...
I am trying to handle the following situation nicely.
In general, let's say I want to have my Angular dialogService to provide a confirm method, which would return a promise resolved on clicking yes button, it means when the confirm actually succeeded. However, I want the dialog would stay open until the internal async operation--which would be executed on yes confirmation--finishes. And if it's finishes successfully, then the dialog should close, otherwise stay open.
In code that would be (perfectly) looking like this:
the outer code:
dialogService.confirm('title', 'message').then =>
return myLongLastingOperationReturningPromise()
the confirm method implementation something like this:
def = $q.defer()
dialog = ngDialog.open(...)
// closePromise or any other custom local promise
dialog.closePromise.then =>
// this is fake, but how can I achieve this?
result = def.resolve('closeRequest');
if(typeof result.then == 'function') {
result.then =>
// continue closing the dialog
} else if (result === false) {
// just do nothing
} else {
// closing the dialog
}
in other words, is there any way to obtain the result of the last then method in the promises chain on/after calling resolve?
You should execute the confirm after the API has successfully returned.
e.g. Click 'yes' button will execute method YesHandler:
In caller: