1
我遇到的问题是有点难以解释,我可能会得到(角)承诺不对,但仍...
我想很好地处理了下面的情况。 一般来说,假设我想让我的Angular dialogService
提供一个confirm
方法,该方法将返回一个单击yes
按钮时解析的承诺,这意味着确认实际上成功了。但是,我希望该对话框会保持打开状态,直到内部async
操作 - 将在yes
确认中执行 - 完成。如果成功完成,那么对话框应该关闭,否则保持打开状态。
在代码,将(完全)看起来像这样:
外码:
dialogService.confirm('title', 'message').then =>
return myLongLastingOperationReturningPromise()
的confirm
方法的实现是这样的:
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
}
换句话说
,有没有办法在拨打resolve
之后得到Promise链中最后一个then
方法的结果?
嗨,你检查这个答案? –