【问题标题】:Put a line break (newline) into a toastr message in AngularJS?在AngularJS中将换行符(换行符)放入toastr消息中?
【发布时间】:2015-09-24 02:35:49
【问题描述】:

我正在使用这个code 在 AngularJS 网站上显示祝酒词。我需要知道如何在正文中添加换行符 (<br/>)。当我使用question 中显示的选项时,toastr 会在屏幕上呈现标签,而不是将其解释为 HTML。如何在 toast 中换行?

【问题讨论】:

    标签: javascript angularjs toastr


    【解决方案1】:

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

    toaster-options 中包含'body-output-type': 'trustedHtml'

    <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>
    

    或者在对toaster.pop()的调用中包含'trustedHtml'

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

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

    Source

    【讨论】:

    • 只是一个小观察,在使用命名参数的第二个示例中,'text'(它不存在)属性应替换为'body'。除此之外,感谢您的广泛回答。
    • @jmrivas 我编辑了答案,很好的发现
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2023-04-07
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    相关资源
    最近更新 更多