简体   繁体   中英

How to use the aurelia-dialog plugin with Aurelia?

I'm having trouble setting up the aurelia-dialog plugin (0.2.0) with my test Aurelia app.

Unfortunately, the README.MD file that details how to accomplish this has some serious holes. First, it doesn't mention having to inject the aureliaDialog into your class, so I tried this first:

@inject(HttpClient, DialogService)
export class MyClass{
  constructor(http, dialogService) {
    this.http = http;
    this.dialogService = dialogService;
  }
  ...
}

I tried to invoke the dialog box using:

this.dialogService.open({ viewModel: Prompt, model: 'Good or Bad?' })

The above results in the following errors:

Unhandled promise rejection ReferenceError: info is not defined
    at Container.invoke (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection@0.10.0/aurelia-dependency-injection.js:401:30)
    at Array.<anonymous> (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection@0.10.0/aurelia-dependency-injection.js:272:44)
    at Container.get (http://127.0.0.1:9000/jspm_packages/github/aurelia/dependency-injection@0.10.0/aurelia-dependency-injection.js:329:24)
    at http://127.0.0.1:9000/jspm_packages/github/aurelia/templating@0.15.1/aurelia-templating.js:3685:75
    at run (http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/es6.promise.js:91:43)
    at http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/es6.promise.js:105:11
    at module.exports (http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/$.invoke.js:6:25)
    at queue.(anonymous function) (http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:40:9)
    at Number.run (http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:27:7)
    at listner (http://127.0.0.1:9000/jspm_packages/npm/core-js@0.9.18/modules/$.task.js:31:9) Unhandled promise rejection ReferenceError: info is not defined(…)(anonymous function) @ es6.promise.js:139module.exports @ $.invoke.js:6queue.(anonymous function) @ $.task.js:40run @ $.task.js:27listner @ $.task.js:31

Next, I tried to add the configuration of the plugin to my main.js file:

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .plugin('aurelia-animator-css')
    .plugin('aurelia-dialog'); // <----- this is what I added

  aurelia.start().then(a => a.setRoot());
}

Now my app doesn't start at all and produces the following error while trying (and failing) to start:

DEBUG [aurelia] Configured plugin aurelia-dialog. aurelia-logging-console.js:38 
DEBUG [templating] importing resources for undefined [] es6.promise.js:139 
  Unhandled promise rejection Error: Cannot read property 'querySelectorAll' of undefined(…)
  (anonymous function) @ es6.promise.js:139module.exports @ $.invoke.js:6queue.
  (anonymous function) @ $.task.js:40run @ $.task.js:27listner @ $.task.js:31

I am now at a loss of what to try next. Thanks for any insight you can offer with this issue.

I'm also hopeful that the maintainer of the aurelia-dialog plugin revises the docs to make the setup process less painful.

Thanks, Greg

In the end, the problem turned out to be a bug in aurelia-dialog 0.2.0. Version 0.2.1 fixes the issue I couldn't resolve on my own: https://github.com/aurelia/dialog/pull/24 .

The other steps that I had to follow are still necessary - you will need to inject the DialogService class and modify your main.js file to add the configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM