Resultado
Ejemplo utilizando caller de tipo ModelOptions (uso interno de componente ModalComponent)
Componente
@Component({
selector: '...',
templateUrl: '...',
...
})
export class DemoDialogComponent {
...
constructor(private dialogService: DialogService, private viewContainerRef: ViewContainerRef) { }
open(): void {
const dialogOptions: DialogOptions = {
id: 'dialog',
dismissOnBackdrop: true,
focusOnClose: 'dialog-btn',
};
const modalOptions: ModalOptions = {
id: 'modal',
title: {
text: 'Editar servicio publicado',
classes: ''
},
description: {
html: '<p>Actualmente este servicio está publicado.</p><p>Los cambios realizados no serán visibles hasta que sean validados</p>',
},
itemsPrimary: [
{
text: 'Editar servicio',
classes: 'c-button--primary'
}
],
isDismissible: true,
classes: 'relative max-w-lg mx-auto p-base lg:p-lg border border-neutral-base rounded bg-white mt-2xl'
};
this.dialogService.openDialog(this.viewContainerRef, modalOptions, dialogOptions).then(result => {
this.dialogService.onCloseDialog(result.dialog).then(() => console.log('Se ha cerrado el dialog'));
});
}
...
}
HTML
<desy-button text="Abrir dialog" (clickEvent)="open()" [id]="'dialog-btn'"></desy-button>
Ejemplo utilizando caller de tipo TemplateRef (template personalizada)
Componente
@Component({
selector: '...',
templateUrl: '...',
...
})
export class DemoDialogComponent {
...
constructor(private dialogService: DialogService, private viewContainerRef: ViewContainerRef) { }
open(modalRef: TemplateRef<any>): void {
const dialogOptions: DialogOptions = {
id: 'dialog',
dismissOnBackdrop: true,
focusOnClose: 'dialog-btn',
};
this.dialogService.openDialog(this.viewContainerRef, modalRef, dialogOptions).then(result => this.dialog = result.dialog.instance);
}
close(): void {
if (this.dialog) {
this.dialogService.closeDialog(this.dialog);
this.dialog = null;
}
}
...
}
HTML
<desy-button text="Abrir dialog" (clickEvent)="open(modal)" [id]="'dialog-btn'"></desy-button>
<ng-template #modal>
<desy-modal [id]="'caller-example'"
classes="relative max-w-lg mx-auto p-base lg:p-lg border border-neutral-base rounded bg-white mt-2xl"
[isDismissible]="true"
[title]="{text:'Editar servicio publicado'}"
[description]="{html:'<p>Actualmente este servicio está publicado.</p><p>Los cambios realizados no serán visibles hasta que sean validados</p>'}"
[itemsPrimary]="[{text:'Editar servicio','classes':'c-button--primary'}]"
(closeModal)="close()">
</desy-modal>
</ng-template>
Ejemplo utilizando caller de tipo Type (componente personalizado)
Componente
@Component({
selector: '...',
templateUrl: '...',
...
})
export class DemoDialogComponent {
...
constructor(private dialogService: DialogService, private viewContainerRef: ViewContainerRef) { }
open(): void {
const dialogOptions: DialogOptions = {
id: 'dialog',
dismissOnBackdrop: true,
focusOnClose: 'dialog-btn',
};
this.dialogService.openDialog(this.viewContainerRef, ModalComponent, dialogOptions).then(result => {
result.component.instance.title = {
text: 'Editar servicio publicado',
classes: ''
};
result.component.instance.description = {
html: '<p>Actualmente este servicio está publicado.</p><p>Los cambios realizados no serán visibles hasta que sean validados</p>',
};
result.component.instance.itemsPrimary = [
{
text: 'Editar servicio',
classes: 'c-button--primary'
}
];
result.component.instance.isDismissible = true;
result.component.instance.id = 'modal';
result.component.instance.classes = 'relative max-w-lg mx-auto p-base lg:p-lg border border-neutral-base rounded bg-white mt-2xl';
const subscription = result.component.instance.closeModal.subscribe(() => {
this.dialogService.closeDialog(result.dialog);
subscription.unsubscribe();
});
});
}
...
}
HTML
<desy-button text="Abrir dialog" (clickEvent)="open()" [id]="'dialog-btn'"></desy-button>