我有一个启动确认对话框的视图,但不是等待对话框返回结果,而是直接跳转到承诺的“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;
}
}
Run Code Online (Sandbox Code Playgroud)
确认对话框.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>
Run Code Online (Sandbox Code Playgroud)
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..'
});
});
}
}
Run Code Online (Sandbox Code Playgroud)
我省略了视图的 html,因为它可以工作并且所有绑定都正确触发。这曾经奏效,我更新了导致运行时错误的 aurelia-bundler,因此我恢复到先前版本的 bundler。运行时错误停止了,但现在似乎 Promise 被短路了。我什至尝试从版本控制中检查项目,但这种情况一直在发生。尝试清除浏览器缓存以防出现问题,但无论我做什么,“为什么会发生这种情况......”总是在确认对话框发生任何交互之前显示。当我在 InfoDialog 上单击“确定”时,确认对话框在下方,然后单击取消或确定不执行任何操作。
任何帮助,将不胜感激。
小智 5
这很可能是因为 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 博客中还有一篇博文:http : //blog.aurelia.io/2017/04/27/aurelia-dialog-release-candidate/
| 归档时间: |
|
| 查看次数: |
742 次 |
| 最近记录: |