Search code examples
angularangular-materialdialogprojection

Angular Material Dialog - content projection


Is it possible to use dynamic content inside an angular material dialog?

let dialogRef = dialog.open(YourDialog, {
  data: { name: 'austin' },
});

Instead of { name: 'austin' }, I would like to use a dynamic template which includes html tags.

@Component({
  selector: 'your-dialog',
  template: 'passed in {{ data.name }}',
  // template: '{{ data.template }}'
})
export class YourDialog {
  constructor(@Inject(MAT_DIALOG_DATA) public data: any) { }
}

Solution

  • Yes just instead of use {{ }} use something like this

    [innerHTML]="data.template"
    

    in a div for example