primeNG confirm dialog message show as html

為{幸葍}努か 提交于 2019-12-08 11:48:12

问题


I need to show confirm dialog message as html, this is how looks my dialog in component:

this.confirmationService.confirm({
        header: "Change user status",
        message: "Do you want to change user status to <strong>" + status + "</strong >?",
        accept: () => {
            //
        }
    });

and this is how it looks like on a page:

I tried to do this two ways but without success

<p-confirmDialog width="500" appendTo="body">
<template pTemplate="body">
    <span class="ui-confirmdialog-message">{{message}}</span>
</template>

<p-confirmDialog width="500" [innerHTML]="message"></p-confirmDialog>

回答1:


PrimeNG ConfirmDialog's message element class is ui-confirmdialog-message

Set up a property (e.g: message) in your ts file

        public message: string;
    ...
        this.confirmationService.confirm({
            header: "Change user status",
            message: this.message,
            accept: () => {
                //
            }
        });

       this.message = document.getElementsByClassName('ui-confirmdialog-message')[0].innerHTML = "Do you want to change user status to <span id='someOtherId'>" + status + "</span >?"

Then in your root styles.css, add this:

.ui-confirmdialog-message span#someOtherId { color: yourColor};

You can console.log "document.getElementsByClassName('ui-confirmdialog-message')" first to see what's in it. I got an array and the [0] element contains my initial ConfirmDialog message.

There might be a better way but I just happened to tackle this after seeing your question and it worked for me.Check this result



来源:https://stackoverflow.com/questions/44063027/primeng-confirm-dialog-message-show-as-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!