How can toastr.js work in Aurelia and Typescript?

寵の児 提交于 2019-12-05 06:15:21

After a lot of time and help from a friend, I was finally able to get this to work.

Only a few changes should be necessary -

aurelia.json needed to be updated to not use the minified version of the toastr library.

{
  //...
  "dependencies": [
  //...
    "jquery",
    {
      "name": "toastr",
      "path": "../node_modules/toastr",
      "main": "toastr",
      "resources": [
        "build/toastr.min.css"
      ],
      "deps": ["jquery"]
    }
  ]
}

The toastr.info('here'); function invocation usually needs to happen in the attached method or after the element is available in the DOM.

To require the HTML in app.html needs to be updated to

<require from="toastr/build/toastr.min.css"></require>

Hope this helps.


UPDATE Then to use it in your view model, you could do it one of a few ways:

import * as toastr from 'toastr';

export class App {
  attached() {
    toastr.success('here');
  }
}

import { success } from 'toastr';

export class App {
  attached() {
    success('here');
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!