UNPKG

ngx-bootstrap-confirm

Version:

Bootstrap confirm provider for Angular 11+

83 lines (76 loc) 2.52 kB
import { Component, Injectable, NgModule } from '@angular/core'; import { BsModalRef, BsModalService, ModalModule } from 'ngx-bootstrap/modal'; import { Subject } from 'rxjs'; class NgxBootstrapConfirmComponent { constructor(bsModalRef) { this.bsModalRef = bsModalRef; } ngOnInit() { this.onClose = new Subject(); } confirm() { this.onClose.next(true); this.bsModalRef.hide(); } decline() { this.onClose.next(false); this.bsModalRef.hide(); } } NgxBootstrapConfirmComponent.decorators = [ { type: Component, args: [{ selector: 'lib-ngx-bootstrap-confirm', template: ` <div class="confirm modal-body"> <div class="content" [innerHTML]="title"></div> <div class="buttons"> <button type="button" class="btn btn-success" (click)="confirm()" [innerHTML]="confirmLabel"></button> <button type="button" class="btn btn-danger" (click)="decline()" [innerHTML]="declineLabel"></button> </div> </div> ` },] } ]; NgxBootstrapConfirmComponent.ctorParameters = () => [ { type: BsModalRef } ]; class NgxBootstrapConfirmService { constructor(modalService) { this.modalService = modalService; } confirm(options) { return new Promise((resolve, reject) => { this.modalRef = this.modalService.show(NgxBootstrapConfirmComponent); this.modalRef.content.title = options.title; this.modalRef.content.confirmLabel = options.confirmLabel; this.modalRef.content.declineLabel = options.declineLabel; this.modalRef.content.onClose.subscribe((result) => { resolve(result); }); }); } } NgxBootstrapConfirmService.decorators = [ { type: Injectable } ]; NgxBootstrapConfirmService.ctorParameters = () => [ { type: BsModalService } ]; class NgxBootstrapConfirmModule { } NgxBootstrapConfirmModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxBootstrapConfirmComponent], imports: [ModalModule.forRoot()], exports: [NgxBootstrapConfirmComponent], providers: [NgxBootstrapConfirmService], },] } ]; /* * Public API Surface of ngx-bootstrap-confirm */ /** * Generated bundle index. Do not edit. */ export { NgxBootstrapConfirmComponent, NgxBootstrapConfirmModule, NgxBootstrapConfirmService }; //# sourceMappingURL=ngx-bootstrap-confirm.js.map