Unable to display Toast message in Angular 5

本秂侑毒 提交于 2019-11-28 06:38:36

问题


Hi I am developing web application in Angular 5. I am trying to display toast message in Angular 5 using https://www.npmjs.com/package/ngx-toastr. I have downloaded required npm modules and copied css to assets folder. Also I have added

import { ToastrModule } from 'ngx-toastr';

in app.component.ts.

I am trying to display toast message as

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

When I run my solution I get below error.

When I run npm install, I get below warnings,

Can someone help me to figure out the issue? Any help would be appreciated. Thank you.


回答1:


Make sure you imported ToastrModule in app.module.ts

import {ToastrModule} from 'ngx-toastr';

in your component, you need to import the provider

import { ToastrService } from 'ngx-toastr';

injector in the constructor as DI

constructor(public toastr: ToastrService) {}

And you can invoke it as

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

EDIT

You need to move to angular6 inorder to make it work. Check the related issue here



来源:https://stackoverflow.com/questions/52940941/unable-to-display-toast-message-in-angular-5

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