在AngularJS中如何将一个换行符(newline)放入toastr消息中?

17

我正在使用这个代码在AngularJS网站上显示通知。 我需要知道如何在内容中添加换行符(<br/>)。当我使用这个问题中显示的选项时,toastr会将标签呈现在屏幕上,而不是将其解释为HTML。 如何在toast中插入换行符?

1个回答

24

允许toast中包含某些HTML标签的方法有两种,包括换行符。

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

或者在调用 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


1
只是一个小观察,在第二个例子中,当使用命名参数时,“text”(它不存在)属性应该被替换为“body”。除此之外,感谢详细的回答。 - jmrivas
1
@jmrivas 我编辑了答案,找得不错。 - jaycer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接