You can create custom modal component like:
export class CustomModalContext extends BSModalContext {
yesCallback: () => Promise<any>;
}
@Component({
selector: 'modal-content',
template: `
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" (click)="dialog.close()">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title">Confirmation</h3>
</div>
<div class="modal-body">
<h4>Are you sure you want to delete the user?</h4>
</div>
<div class="modal-footer">
<button class="btn btn-primary" (click)="yes()">Yes</button>
<button class="btn" (click)="dialog.close()">No</button>
</div>
</div>`
})
export class CustomModal implements CloseGuard, ModalComponent<CustomModalContext> {
context: CustomModalContext;
constructor(public dialog: DialogRef<CustomModalContext>) {
this.context = dialog.context;
dialog.setCloseGuard(this);
}
yes() {
this.context.yesCallback()
.then(() => this.dialog.close())
}
beforeDismiss(): boolean {
return true; // prevent closing modal by using Esc
}
}
Then add it to declarations
and entryComponents
of your @NgModule
metadata
declarations: [ App, CustomModal ],
entryComponents: [CustomModal],
bootstrap: [ App ]
})
export class AppModule {}
And use it as follows
deleteUser() {
return this.modal.open(CustomModal,
overlayConfigFactory({
yesCallback: () => {
alert('Deleting');
return Promise.resolve(null)
}
}, BSModalContext));
}
Plunker Example