首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角5 ngx-toastr不显示html消息

角5 ngx-toastr不显示html消息
EN

Stack Overflow用户
提问于 2018-10-31 06:48:41
回答 2查看 6.2K关注 0票数 5

我用的是角5和ngx-烤面包圈。我使用了以下代码,它将HTML与消息一起呈现,比如:Hi<b>Hello</b>,这是不需要的。

代码语言:javascript
复制
this.toastr.warning("Hi<b>Hello</b>");

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

代码语言:javascript
复制
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中启用HTML,使消息看起来像: hiHello

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-31 07:04:49

按参数的顺序更改配置,

代码语言:javascript
复制
this.toastr.show('<font color=\"red\">Hi<b>Hello</b></red></font>"',
           'title' , {
                    enableHtml: true,
                    closeButton: true,
                    timeOut: 10000
                });

STACKBLITZ演示

票数 12
EN

Stack Overflow用户

发布于 2022-07-01 09:34:35

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

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53077782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档