【问题标题】:How to use plain toastr.js with angular 2?如何在 Angular 2 中使用普通的 toastr.js?
【发布时间】:2016-11-11 10:11:46
【问题描述】:

使用 angular 2 设置和使用 toastr 的步骤如下: https://codeseven.github.io/toastr/

我正在使用 Angular 2 + Typescript + Webpack + npm 组合。

我尝试做一个 npm install toastr 并将其导入我的项目中,然后是 declare var toastr :any; 这些都没有帮助

请指导

【问题讨论】:

    标签: angular typescript toastr


    【解决方案1】:

    TypeScript 需要定义文件才能使用 JS,而 toastr 库没有。

    但是,您可以使用Typings 来获取 d.ts 文件。
    typings install dt~toastr --global --save
    如果需要,还可以添加 JQuery 的定义文件。

    现在您可以在您的组件中使用 toastr 并记住在 vendor.ts 中导入 css。
    import * as toastr from 'toastr';
    toastr.error('Title', 'Error message');

    【讨论】:

    • 谢谢我去试试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 2018-04-10
    • 2016-12-25
    相关资源
    最近更新 更多