Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use html in primeng p-toast

I would like to use html code
in primeng toast module. I have tried different options but cannot get it to work.

this.messageService.add({ sticky: true, severity: 'error', summary: 'Import job', detail: 'first line of text <br\>second line of text'});

anyone suggestions?

like image 401
R.M. van Lingen Avatar asked Sep 24 '18 15:09

R.M. van Lingen


2 Answers

In order to use an HTML content in the p-toast, you can use a very simple custom message template.

<p-toast position="top-center">
    <ng-template let-message pTemplate="message">
        <p innerHtml="{{message.detail}}"></p>
    </ng-template>
</p-toast>

No extra variable needed, the template uses the message variable which is native to the Primeng component.

like image 155
Daniel Olszewski Avatar answered Oct 21 '22 09:10

Daniel Olszewski


Actually you can with a little tick in CSS, declaring this in your main sylesheet:

.ui-toast-detail {
   white-space: pre-line;
}

Now yours \n will work in the message :)

like image 9
Jesé Romero Avatar answered Oct 21 '22 11:10

Jesé Romero