简体   繁体   中英

Angular / Angular Material - How to Project Content with inside MatDialog.open(Component)

For example if I have Component:

@Component(
  selector: "demo-comp",
  template: `
    <div>
      Some text...
      <ng-content></ng-content>
    </div>
  `
)
export class DemoComponent {
  constructor(public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data)
  // ...
}

Is there a proper way to project content while opening a dialog? I know only this way to open the dialog... which not allowing me to pass content to the slot.

// Inside another component
constructor(dialog: MatDialog) {}
open = () => {
  this.dialog.open(DemoComponent, {/** someConfig */ })
}

NOTE: I accept answers with portals and etc.

there is no dialog API way to project content inside of the dynamic component. However you could create wrapper component, which would render the original component with some content projected inside of it

@Component({
  ...,
  template: `<demo-component [data]="data"><div>project something</div>`
})
exprt class DemoProjectionDialogComponent {
...
}
...
this.dialog.open(DemoProjectionDialogComponent, {...})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM