In my Angular 4 app, let\'s assume that I\'m inside a service.
At some point, I want to ask the user for a confirmation, currently I\'m doing it with just a co
Try this:
home.component.ts
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal';
export class HomeComponent {
public modalRef: BsModalRef;
constructor(
private modalService: BsModalService
) { }
openConfirmDialog() {
this.modalRef = this.modalService.show(HomeModalComponent);
this.modalRef.content.onClose = new Subject();
this.modalRef.content.onClose.subscribe(result => {
console.log('results', result);
})
}
}
and
home-modal.component.ts
import { BsModalRef } from 'ngx-bootstrap/modal';
export class HomeModalComponent {
constructor(private bsModalRef: BsModalRef) {
}
public ngOnInit(): void {
}
public onConfirm(): void {
this.bsModalRef.content.onClose.next(true);
this.bsModalRef.hide();
}
public onCancel(): void {
this.bsModalRef.content.onClose.next(false);
this.bsModalRef.hide();
}
}