Angular 5 ngx烤面包机未显示html消息



我使用Angular 5和ngx烤面包机。我使用了以下代码来呈现HTML标记和消息,如:Hi<b>Hello</b>,这是不期望的。

this.toastr.warning("Hi<b>Hello</b>");

此外,我使用了以下代码,它没有控制台错误,也没有任何输出(弹出(:

this.toastr.show("<font color="red">Hi<b>Hello</b></red></font>",null,{
disableTimeOut: true,
tapToDismiss: false,
closeButton: true,
positionClass:'bottom-left',
enableHtml:true
});

如何在ngx-toast中启用HTML,以便消息看起来像:你好你好

按照参数事项的顺序更改配置,

this.toastr.show('<font color="red">Hi<b>Hello</b></red></font>"',
'title' , {
enableHtml: true,
closeButton: true,
timeOut: 10000
});

STACKBLITZ演示

我如下解决了这个问题,您可以设置IndividualConfig这些设置。

export class NotificationService {
public toastrConfig: Partial<IndividualConfig> = {
timeOut: 20000,
extendedTimeOut: 20000,
enableHtml: true
};
constructor(private notifyService: ToastrService) {

}
setNotification(type: MessageType, message?: string, statusCode?: number, panelName?: string, err?: any) {
switch (type) {
case MessageType.Success:
this.notifyService.success(message ? message : 'Başarılı: .', "İşlem Başarılı Olmuştur");
break;
case MessageType.Info:
this.notifyService.info(message ? message : 'Uyarı: .', panelName);
break;
case MessageType.Danger:
let exceptionMessage = err === undefined ? "" : err;
if (panelName) {
exceptionMessage += '<div style="margin-bottom: 4px">Panel adı: <span style="font-weight: bold">' + panelName + '</span> </div>';
}
if (statusCode) {
exceptionMessage += 'Durum kodu: ' + statusCode + '<br>';
}
if (!message) {
exceptionMessage += 'İşlem başarısız.';
} else {
exceptionMessage += message;
}
this.notifyService.error(exceptionMessage, panelName);
break;
default:
break;
}
}

[stackblitz1

最新更新