Aurelia Dialog 在对话 returns 之前运行 'then'
Aurelia Dialog runs 'then' before dialog returns
我有一个启动确认对话框的视图,但代码没有等待对话框 return 结果,而是直接跳转到承诺的 'then' 部分。请参阅下面的代码:
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 正在短路。我什至尝试从版本控制中检查项目,但这种情况一直在发生。尝试清除浏览器缓存以防出现问题,但无论我做什么,"why is this happening..." 总是在确认对话框发生任何交互之前显示。当我在 InfoDialog 上单击 'ok' 时,下方会出现确认对话框,随后单击取消或确定不会执行任何操作。
如有任何帮助,我们将不胜感激。
这很可能是因为 beta 和 RC 之间的 aurelia-dialog 发生了重大变化。
尝试将 this.dialogService.open({...}).then(...)
更改为 this.dialogService.open({...}).whenClosed().then(...)
。
请参阅 RC-1 的发行说明:https://github.com/aurelia/dialog/releases/tag/1.0.0-rc.1。
Aurelia 博客中还有一个博客 post:http://blog.aurelia.io/2017/04/27/aurelia-dialog-release-candidate/
我有一个启动确认对话框的视图,但代码没有等待对话框 return 结果,而是直接跳转到承诺的 'then' 部分。请参阅下面的代码:
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 正在短路。我什至尝试从版本控制中检查项目,但这种情况一直在发生。尝试清除浏览器缓存以防出现问题,但无论我做什么,"why is this happening..." 总是在确认对话框发生任何交互之前显示。当我在 InfoDialog 上单击 'ok' 时,下方会出现确认对话框,随后单击取消或确定不会执行任何操作。
如有任何帮助,我们将不胜感激。
这很可能是因为 beta 和 RC 之间的 aurelia-dialog 发生了重大变化。
尝试将 this.dialogService.open({...}).then(...)
更改为 this.dialogService.open({...}).whenClosed().then(...)
。
请参阅 RC-1 的发行说明:https://github.com/aurelia/dialog/releases/tag/1.0.0-rc.1。
Aurelia 博客中还有一个博客 post:http://blog.aurelia.io/2017/04/27/aurelia-dialog-release-candidate/