您好,我正在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!');
运行解决方案时,出现以下错误。
运行npm install时,出现以下警告
答案 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