javascript 将换行符(换行符)放入 AngularJS 中的 toastr 消息中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31254459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:32:58  来源:igfitidea点击:

Put a line break (newline) into a toastr message in AngularJS?

javascriptangularjstoastr

提问by jaycer

I'm using this codeto display toasts on an AngularJS site. I need to know how to put a line break (<br/>) into the body. When I use the options shown in this question, toastr renders the tag on screen, rather than interpreting it as HTML. How can I get a line break into a toast?

我正在使用此代码在 AngularJS 站点上显示吐司。我需要知道如何将换行符 ( <br/>) 放入正文中。当我使用此问题中显示的选项时,toastr 在屏幕上呈现标签,而不是将其解释为 HTML。我怎样才能让换行变成吐司?

回答by jaycer

There are two ways to allow some HTML tags, including line breaks, in a toast.

有两种方法可以在 Toast 中允许某些 HTML 标记,包括换行符。

Include 'body-output-type': 'trustedHtml'in toaster-options:

包括'body-output-type': 'trustedHtml'toaster-options

<toaster-container toaster-options="{
    'closeButton': false,
    'debug': false,
    'position-class': 'toast-bottom-right',
    'onclick': null,
    'showDuration': '200',
    'hideDuration': '1000',
    'timeOut': '5000',
    'extendedTimeOut': '1000',
    'showEasing': 'swing',
    'hideEasing': 'linear',
    'showMethod': 'fadeIn',
    'hideMethod': 'fadeOut', 
    'body-output-type': 'trustedHtml'
}"></toaster-container>

Or include 'trustedHtml'in a call to toaster.pop():

或者包括'trustedHtml'在调用中toaster.pop()

toaster.pop('success', 'Saved', 'Saved<br/>it!', 3000, 'trustedHtml');

or

或者

toaster.pop({
    type: 'success',
    title: 'Saved',
    text: 'Saved<br/>it!',
    bodyOutputType: 'trustedHtml'
});

Source

来源