无法在Angular 5中显示Toast消息

时间:2018-10-23 03:57:08

标签: angular angular5 angular-toastr

您好,我正在Angular 5中开发Web应用程序。我正在尝试使用https://www.npmjs.com/package/ngx-toastr在Angular 5中显示烤面包消息。我已经下载了所需的npm模块并将CSS复制到资产文件夹。我还添加了

  

从'ngx-toastr'导入{ToastrModule};

在app.component.ts中。

我正在尝试将烤面包消息显示为

  

this.toastr.success('Hello world!','Toastr fun!');

运行解决方案时,出现以下错误。

enter image description here

运行npm install时,出现以下警告

enter image description here 有人可以帮我解决这个问题吗?任何帮助,将不胜感激。谢谢。

enter image description here

1 个答案:

答案 0 :(得分:1)

确保在 ToastrModule

中导入了 app.module.ts
import {ToastrModule} from 'ngx-toastr';

在您的组件中,您需要导入提供程序

import { ToastrService } from 'ngx-toastr';

构造函数中的注入器为DI

constructor(public toastr: ToastrService) {}

您可以将其调用为

this.toastr.success(message, 'Success!');

编辑

您需要移动到angular6才能使其工作。检查相关问题 here