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
@ShinDarth You can add this function in your service and call this funcion whenever required.
In your Service, create this function
openConfirmDialogBox() {
this.modalRef = this.modalService.show(DemoModalComponent);
this.modalRef.content.action.take(1)
.subscribe((value) => {
console.log(value) // here value passed on clicking ok will be printed in console. Here true will be printed if OK is clicked
return value;
}, (err) => {
return false;
});
}
In your demo-modal.component.ts, create an EventEmitter
@Output() action = new EventEmitter();
public onClickOK() {
this.action.emit(true); //Can send your required data here instead of true
}
public onClickCANCEL() {
this.action.emit(false); //Can send your required data here instead of true
}
I hope this would help you