src/app/core/confirm-dialog/confirm-dialog.component.ts
selector | crm-confirm-dialog |
styleUrls | confirm-dialog.component.scss |
templateUrl | ./confirm-dialog.component.html |
Properties |
|
Methods |
constructor(confirmDialogService: ConfirmDialogService)
|
||||||||
Parameters :
|
hideModal |
hideModal()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onConfirm |
onConfirm()
|
Returns :
void
|
showModal |
showModal()
|
Returns :
void
|
button |
button:
|
Type : string
|
Private confirmDialogModal |
confirmDialogModal:
|
Type : ModalDirective
|
Decorators : ViewChild
|
message |
message:
|
Type : string
|
Private subscription |
subscription:
|
Type : Subscription
|
title |
title:
|
Type : string
|
import {Component, OnInit, ViewChild, OnDestroy} from '@angular/core';
import {ModalDirective} from "ngx-bootstrap/modal";
import {Subscription} from "rxjs";
import {ConfirmDialogService} from "./confirm-dialog.service";
@Component({
selector: 'crm-confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.scss']
})
export class ConfirmDialogComponent implements OnInit, OnDestroy {
@ViewChild('confirmDialogModal') private confirmDialogModal: ModalDirective;
private subscription: Subscription;
title: string;
message: string;
button: string;
constructor(private confirmDialogService: ConfirmDialogService) {
}
ngOnInit() {
this.subscription = this.confirmDialogService.askState.subscribe(data => {
this.title = data.title;
this.message = data.message;
this.button = data.button;
this.showModal();
});
this.subscription.add(this.confirmDialogModal.onHide.subscribe(() => this.confirmDialogService.cancel()))
}
ngOnDestroy() {
this.subscription.unsubscribe()
}
showModal() {
this.confirmDialogModal.show();
}
hideModal() {
this.confirmDialogModal.hide();
}
onConfirm() {
this.confirmDialogService.confirm();
this.hideModal();
}
}
<div bsModal #confirmDialogModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h6>{{title}}</h6>
<button type="button" class="close" (click)="hideModal()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>{{message}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="hideModal()">Cancel</button>
<button type="button" class="btn btn-danger" (click)="onConfirm()">{{button}}</button>
</div>
</div>
</div>
</div>