angular - Angular Notifier 中的新行
问题描述
由于我找不到这个决定,这里是 Angular 6 的一个简单问题。我正在使用angular 6
服务angular-notofier
,我试图为用户显示一个简单的多行消息。
我尝试过使用 HTML 标签<br/>
和换行符"\n"
,但没有成功。看起来有字符串转义XSS
或其他东西,我无法添加新行。
如果我可以那样做或者我试图以错误的方式做,有什么想法(如果是这样,那么为什么它是错的,我应该怎么做?)?
我想避免更复杂的结构,比如自定义模板(尽管我怀疑问题也应该出现在那里)。
这是我的“代码”:
constructor(
private notifier: NotifierService,
...
this.notifier.notify(
'error',
'Multiline' + "\n" + ' message will <br/> print in one line...' ....
非常感谢!安东
解决方案
如果您想传递您的自定义消息,那么您可以利用该模板。通过模板,您可以完全控制消息的显示方式。
在 HTML 中
是的,您需要在 html 中使用模板来获得包含多行的自定义消息。
<ng-template #notification let-notificationData="notification">
<span [innerHTML]="notificationData.message"></span>
</ng-template>
在 ts
@ViewChild('notification') notificationTemplate;
this.notifier.show({
message: msg.message,
type: msg.messageType,
template: this.notificationTemplate //<-- template name from html.
});
有关更多详细信息,请查看官方文档 - https://www.npmjs.com/package/angular-notifier
推荐阅读
- c# - C# 分配一个类数组,但值被视为 0
- java - 部署为 jar 文件的微服务和 Rest 服务?
- reactjs - 如何使用本机反应制作类似于 Instagram 的类似功能(点赞按钮)
- android - 离线时不使用 Exoplayer 缓存进行播放
- laravel - Laravel 模型与 Where & orWhere 语句的关系
- amazon-web-services - dynamodb PITR 替换脚本快照?
- php - 如何从 Braintree 的 JSON 响应中获取 ID?
- android - pkg-config 在 ffmpeg 构建(linux)上找不到库
- dart - 使用 PageView 预加载网络图像
- android - Android加载大图像进行打印