Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass HTML into Mat Dialog [duplicate]

I am trying to pass HTML into my Mat Dialog code as the message parameter. So I have the following but am not sure how I can pass HTML into it.

  openAlertDialog() {
    const dialogRef = this.dialog.open(AlertDialogComponent,{
      data:{
        message: '<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>',
        buttonText: {
          cancel: 'Done'
        }
      },
    });
  }

I want to add HTML in the message

I have a stackblitz of the code here https://stackblitz.com/edit/mat-dialog-example-kchzml?file=app/app.component.ts

Any idea how I can do this?

like image 350
RRB Avatar asked Sep 18 '25 03:09

RRB


1 Answers

You can display your HTML message using innerHTML attribute. Change it to below.

<mat-dialog-content [innerHTML]="message">
</mat-dialog-content>

Working stackblitz

like image 137
Shabbir Dhangot Avatar answered Sep 19 '25 17:09

Shabbir Dhangot