首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对话框弹出,但“取消”和“确定”不是函数。

对话框弹出,但“取消”和“确定”不是函数。
EN

Stack Overflow用户
提问于 2015-12-31 16:04:27
回答 1查看 828关注 0票数 2

我通常会跟随下面的例子:- https://github.com/aurelia/dialog#using-the-plugin

该模式在我的消息中弹出很好,但是当我单击cancelok时,会得到

未明错误:取消不是一个函数,或者是不正确的错误: ok不是一个函数

它似乎没有跳进承诺,也请注意,如果这是相关的,但我的controller.settings似乎也是空的。

在我的prompt.js

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

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

在我的主要组成部分中

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

  ...

};

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-31 18:05:27

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

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

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

代码语言:javascript
复制
import {DialogService} from 'aurelia-dialog';

@inject(DialogService)

有了这些:

代码语言:javascript
复制
import {DialogController} from 'aurelia-dialog';

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

https://stackoverflow.com/questions/34548795

复制
相关文章

相似问题

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