New line in Angular Notifier

柔情痞子 提交于 2019-12-24 10:29:46

问题


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


回答1:


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.

in html

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>

in ts

 @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



来源:https://stackoverflow.com/questions/53065215/new-line-in-angular-notifier

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