Javascript 类型脚本模式对话框承诺响应
我的应用程序中有一个显示引导对话框的服务。目前代码非常简单:Javascript 类型脚本模式对话框承诺响应,javascript,typescript,promise,Javascript,Typescript,Promise,我的应用程序中有一个显示引导对话框的服务。目前代码非常简单: async showConfirmation(message: string): Promise<boolean> { this.message(message); this.isPopupOpen(true); return false; } 此时,showConfirmation函数立即返回一个硬编码的false,而我想等待用户的响应,并将其作为showConfirmation的结果返回
async showConfirmation(message: string): Promise<boolean> {
this.message(message);
this.isPopupOpen(true);
return false;
}
此时,showConfirmation
函数立即返回一个硬编码的false
,而我想等待用户的响应,并将其作为showConfirmation
的结果返回
我不完全确定实现这一目标的最佳方法。我如何才能让它等待用户返回相应的响应?它的可能副本在同一个大概范围内,但在使用TypeScript时不包括这种情况。我仍然在努力找出如何让它工作,即使有其他答案的内容。
<div role="dialog" aria-hidden="true" class="modal fade" data-bind="modal: { show: isPopupOpen }">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" title="Close" aria-label="Close">×</button>
<h4 class="modal-title">My Modal</h4>
</div>
<div class="modal-body" data-bind="text: message"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" data-bind="click: close">Cancel</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" data-bind="click: close">OK</button>
</div>
</div>
</div>
</div>
close(data, event) {
//console.debug(data);
console.debug(event.target);
this.isPopupOpen(false);
}