首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aurelia Dialog在对话框返回之前运行'then‘

Aurelia Dialog在对话框返回之前运行'then‘
EN

Stack Overflow用户
提问于 2017-08-10 06:14:15
回答 1查看 783关注 0票数 2

我有一个启动确认对话框的视图,但代码不是等待对话框返回结果,而是直接跳到promise的“then”部分。请看下面的代码:

ConfirmDialog.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
<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">&times;</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

代码语言:javascript
复制
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,这导致了一个运行时错误,所以我恢复到以前版本的bundler。运行时错误已停止,但现在似乎Promise正在短路。我甚至试着从版本控制中签出这个项目,但这种情况一直在发生。我试着清除浏览器缓存,以防那里出了什么问题,但无论我做什么,都会问“为什么会发生这种情况...”在与确认对话框发生任何交互之前始终显示。当我在InfoDialog上点击' OK‘时,确认对话框在下方,然后点击cancel或OK什么也不做。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-10 18:06:11

这很可能是因为测试版和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/

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45601447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档