我有一个视图,启动一个确认对话框,但不是等待对话框返回结果,代码直接跳到'然后'承诺的一部分。请参阅以下代码:
ConfirmDialog.ts
import { inject } from 'aurelia-framework';
import { DialogController } from 'aurelia-dialog';
@inject(DialogController)
export class ConfirmDialog {
private message: string;
private controller: DialogController;
constructor(controller: DialogController) {
this.controller = controller;
}
public activate(message: string) {
this.message = message;
}
}
ConfirmDialog.html
<template>
<div tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" click.trigger="controller.cancel()" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
${message}?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" click.trigger="controller.cancel()">No!</button>
<button type="button" class="btn btn-danger" click.trigger="controller.ok()">Yes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</template>
SomeView.ts
import * as moment from 'moment';
import { inject, singleton } from 'aurelia-framework';
import { DialogService } from 'aurelia-dialog';
import { ConfirmDialog } from '../components/modal/confirmDialog';
import { InfoDialog } from '../components/modal/infoDialog';
import { StateStore } from '../common/StateStore';
import { Routing } from '../common/routing';
@singleton()
@inject(Routing, StateStore, DialogService)
export class SomeView {
private routing: Routing;
private commonState: StateStore;
private dialogService: DialogService;
constructor(routing: Routing, stateStore: StateStore, dialogService: DialogService) {
this.routing = routing;
this.commonState = stateStore;
this.dialogService = dialogService;
}
public someButtonClickHandler(someArg: SomeType) {
if (!this.routing.auth.authenticated) {
this.routing.router.navigate('#/login');
}
this.dialogService.open({
viewModel: ConfirmDialog,
model:
'Do you wish to continue'
}).then((response) => {
if (response.wasCancelled) {
return;
}
this.dialogService.open({
viewModel: InfoDialog,
model: 'Why is this happening..'
});
});
}
}
我已经省略了视图的html,因为它可以工作并且所有绑定都正确触发。这曾经工作,我更新了导致运行时错误的aurelia-bundler,所以我又回到了捆绑器的先前版本。运行时错误已停止,但现在看来Promise正在被短路。我甚至尝试从版本控制中检出项目,这种情况一直在发生。尝试清除浏览器缓存,以防出现问题但无论我做什么,&#34;为什么会发生这种情况......&#34;始终在确认对话框中发生任何交互之前显示。当我点击“确定”时在InfoDialog上,确认对话框位于下方并单击取消或OK随后不执行任何操作。
任何帮助都将不胜感激。
答案 0 :(得分:3)
这很可能是因为beta和RC之间的aurelia对话框发生了重大变化。
尝试将this.dialogService.open({...}).then(...)
更改为this.dialogService.open({...}).whenClosed().then(...)
。
请参阅RC-1的发行说明:https://github.com/aurelia/dialog/releases/tag/1.0.0-rc.1。
Aurelia博客上还有一篇博文:http://blog.aurelia.io/2017/04/27/aurelia-dialog-release-candidate/