Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 ngx-toastr not displaying html message

I'm using Angular 5 with ngx-toastr. I have used the following code which renders HTML tag along with the message like: Hi<b>Hello</b> which is not expected.

this.toastr.warning("Hi<b>Hello</b>");

Also, I used the below code which has no console error neither any output (popup):

this.toastr.show("<font color=\"red\">Hi<b>Hello</b></red></font>",null,{
disableTimeOut: true,
tapToDismiss: false,
closeButton: true,
positionClass:'bottom-left',
enableHtml:true
});

How can I enable HTML in ngx-toastr so that message can looks like: hiHello

like image 560
Niladri Banerjee - Uttarpara Avatar asked Oct 31 '18 06:10

Niladri Banerjee - Uttarpara


People also ask

How do I show success notification toasts in angular?

Navigate to the utility folder and create an Angular service. Import the ngx-toastr service inside the NotificationService. Create a method called showSuccess to show success notification toasts. The notification.service.ts file should look similar to this:

How do I add toastr to my angular app?

Adding ngx-toastr to the Angular App. Install ngx-toastr using Node Package Manager (npm). ngx-toastr also requires the @angular/animation package as a dependency. Once you have installed the above packages, open the <project-directory>/angular.json file and include the toastr CSS.

How do I get toasts from NGX notificationservice?

Import the ngx-toastr service inside the NotificationService. Create a method called showSuccess to show success notification toasts. The notification.service.ts file should look similar to this: Import the NotificationService wrapper inside the RootComponent and call the showSuccess method to show toast messages.

How to add a wrapper for NGX-toastr in your angular application?

Let's have a look at how you can add a wrapper for ngx-toastr in your Angular application. Create an Angular service called notification, which you'll use in your application for showing the toastr message. In src/app create a folder called utility. Navigate to the utility folder and create an Angular service.


1 Answers

Change your configuration as follows as the order of parameter matters,

this.toastr.show('<font color=\"red\">Hi<b>Hello</b></red></font>"',
           'title' , {
                    enableHtml: true,
                    closeButton: true,
                    timeOut: 10000
                });

STACKBLITZ DEMO

like image 83
Sajeetharan Avatar answered Oct 09 '22 07:10

Sajeetharan