javascript - 弹出对话框但取消并确定不是功能

标签 javascript aurelia

我通常遵循此处的示例:- https://github.com/aurelia/dialog#using-the-plugin

我的消息可以正常弹出模式,但是当我单击 cancelok 时,我得到了

Uncaught Error :取消不是函数 或者 Uncaught Error :ok 不是函数

它似乎没有跳入 promise ,还要注意确定这是否相关,但我的 controller.settings 似乎也为空。

在我的prompt.js

import {BindingEngine, inject} from 'aurelia-framework';
import {DialogService} from 'aurelia-dialog';

@inject(DialogService)

export class Prompt {

  constructor(controller){
    this.controller = controller;
    this.answer = null;

    //settings seems to be null as well?
    //controller.settings.lock = false;
    //controller.settings.centerHorizontalOnly = true;
  }
  
  activate(message) {
      this.message = message;
  }
}

在我的prompt.html

<template>
  <ai-dialog>
    <ai-dialog-body>
      <h2>${message}</h2>
    </ai-dialog-body>

    <ai-dialog-footer>
      <button click.trigger="controller.cancel()">Cancel</button>
      <button click.trigger="controller.ok()">Ok</button>
    </ai-dialog-footer>
  </ai-dialog>
</template>

在我的主要组件中

...
import {DialogService} from 'aurelia-dialog';
import {Prompt} from './prompt';


@inject(..., DialogService)

export class Welcome {

    constructor(..., dialogService) {
        this.dialogService = dialogService;
    }


    reset() {
        this.dialogService.open({viewModel: Prompt, model: 'Are you sure you want to reset?' }).then(response => {
            console.log(response);
            if (!response.wasCancelled) {
                console.log('OK');
            } else {
                console.log('cancelled');
            }
            console.log(response.output);
        });
    }
    

  ...

};

最佳答案

您可以从 'aurelia-dialog' 导入两个不同的类(以及其他导出类):DialogServiceDialogController

您似乎在 prompt.js 类中导入了 DialogService,但试图将其用作 controller

只需替换 prompt.js 中的这些行:

import {DialogService} from 'aurelia-dialog';

@inject(DialogService)

这些:

import {DialogController} from 'aurelia-dialog';

@inject(DialogController)

关于javascript - 弹出对话框但取消并确定不是功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34548795/

相关文章:

javascript - 无法在页面加载时运行函数(创建元素)

javascript - 模型属性未统一命名的 Backbone 集合和模板

javascript - Mongoose 获取数据,设置在列表中(未定义)

azure-devops - Aurelia 在 VSO 托管构建 Controller 上构建

javascript - ExpressJS 似乎不适用于 ajax 调用

javascript - 尝试从 JavaScript 客户端的 PHP 服务器捕获托管的 PayPalCheckoutSdk.Orders.OrdersCreateRequest 错误

aurelia - @CompatedFrom 抛出 "Cannot set property ' 未定义的依赖项”

javascript - Aurelia 以及导入和使用 Highcharts X-range

typescript - 定义全局 TypeScript 配置(接口(interface)),用于 Aurelia 依赖注入(inject)

javascript - 定义一个等待 promise 返回的 NavigationInstruction