As I cannot find a decision for this, here is a simple question for Angular 6. I am using angular 6
with angular-notofier
service and I am trying to show a simple multiline message for the user.
I have tried using HTML tags <br/>
and New line chars "\n"
but with no success. Looks like there is string escaping against XSS
or something and I cannot add a new line.
Any ideas if I can do it that way OR if I am trying to do it in the wrong way (if so, then why is it wrong and how am I supposed to do it?)?
I would like to avoid more complicated constructions like custom templates (despite I suspect the problem should be presented there also).
Here is my "code":
constructor(
private notifier: NotifierService,
...
this.notifier.notify(
'error',
'Multiline' + "\n" + ' message will <br/> print in one line...' ....
Thanks a lot! Anton
If you want to pass your customized message then you can leverage the template. Through template you can have complete control how a message should be displayed.
yes, you need to use template in html to have custom message including multi line.
<ng-template #notification let-notificationData="notification">
<span [innerHTML]="notificationData.message"></span>
</ng-template>
@ViewChild('notification') notificationTemplate;
this.notifier.show({
message: msg.message,
type: msg.messageType,
template: this.notificationTemplate //<-- template name from html.
});
For more details look at official docs - https://www.npmjs.com/package/angular-notifier