NgbModal as a general reference table

I am trying to create a general confirmation box using ngbmodal, which will be used through the application. In which the header and message will be passed to the modal from the calling component. I created as a DialogService and added to entryComponents. Now I can show a confirmation window. But could not get the result. Below is the code to display the ConfirmationBox component. How to get value from it

    const modalRef = this.modalService.open(ConfirmationBoxComponent,{backdrop:"static"})
    modalRef.componentInstance.name = "Message";
    modalRef.componentInstance.confirmationBoxTitle = "Confirmation?"
    modalRef.componentInstance.confirmationmessage = "Do you want to cancel?"
    modalRef.componentInstance.changeRef.markForCheck();
+4
source share
1 answer

, , IMO: result . , , ( activeModal.close(...)):

<button (click)="activeModal.close(true)">Yes</button>
<button (click)="activeModal.close(false)">No</button>

result NgbModalRef ( modalRef.result.then):

open() {
    const modalRef = this.modalService.open(NgbdModalContent);
    modalRef.componentInstance.confirmationBoxTitle = 'Confirmation?';
    modalRef.componentInstance.confirmationMessage = 'Do you want to cancel?';

    modalRef.result.then((userResponse) => {
      console.log(`User choice: ${userResponse}`)
    });        
  }

plunker: http://plnkr.co/edit/yYIx1m1e2nfK0nxFwYLJ?p=preview

+1

Source: https://habr.com/ru/post/1675613/


All Articles