Ngx-bootstrap: How to pass event emitted by component within modal to parent?

Created on 30 Mar 2017  路  4Comments  路  Source: valor-software/ngx-bootstrap

I have a modal whose content is a custom component used elsewhere in my application. I've designed that component to be agnostic to the fact if it resides within a modal or not. I need the modal to close when a button within the component is clicked, so I had it emit an event. Problem is, the parent component of the modal (grandparent component to the component inside the modal) can't see the event being fired. I believe the event is only within view of the modal.

How do I pass the event emission from the custom component to the modal to the parent component of the modal?

Most helpful comment

@bomberblue07 - can you elaborate on how you accomplished this? I am trying to emit an event to update state via ngrx, not close the model so I am hoping that is possible.
Thanks,
Bob

All 4 comments

Fixed it by telling the notify in the modal to call the method in the grandparent. The simple solution eluded me, I guess.

@bomberblue07 - can you elaborate on how you accomplished this? I am trying to emit an event to update state via ngrx, not close the model so I am hoping that is possible.
Thanks,
Bob

I have the same issue.
How was it solved? Thanks in advance. :)

I was able to solve this by subscribing to the event property emitted by my component , within the function that has access to your modalRef.

openModal() {
    const modalRef = this.modalService.open(AgnosticComponent)
    modalRef.componentInstance["EventEmittedProperty"].subscribe(event => {
     console.log(event) //< you now have access to the event that was emitted, to pass to your grandfather component.
    });
  }
Was this page helpful?
0 / 5 - 0 ratings