1

I have installed toastr in my Aurelia app. I am able to import and use it in different views, but I can't figure out how to set/modify its global options.

Ideas?

1 Answers1

4

The most trivial place to do that is in you application constructor. You must also have your toaster script loaded at this point. Here's how your app.js could look like:

import {Router} from 'aurelia-router';
import toastr from 'toastr';
export class App {
  static inject() { return [Router]; }
  constructor(router) {
    toastr.options.closeButton = true;

    // ... setup your routing etc
  }
}

I assume you already have your toaster script loaded at this point. You can also move toastr initialization to any other Aurelia constructor, or any other place, I don't see any technical restrictions.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • I've put a "import toastr from 'toastr';" in my "app.js" file and it worked. Thanks! – Kostadin Mandulov Apr 24 '15 at 19:59
  • @Mikhail I am trying to understand why the syntax 'import toastr' works ? I cannot make it work for es6 module, I have to use 'import {mymodule} to make it work – sam Apr 26 '15 at 17:25
  • 3
    @sam {..} syntax is actually a destructuring operator. Your es6 module can export multiple things, and you can import multiple things in one line, e.g. import {A, B} from 'my-module'. To use import A from 'my-module' syntax, you have to use "export default" statement. There can only be one default export, so destructuring may be omitted in this case. See this question for samples of both: http://stackoverflow.com/questions/25494365/es6-module-export-options – Mikhail Shilkov Apr 27 '15 at 18:12