1

I'm launching a modal using ngx-bootstrap via this.modalService.show(ListModalComponent, <options>) by passing in the component to the modal (docs link). I need to subscribe to an event emitter in the component to act on change events from inside the modal but I am unable to get a reference to the component because it doesn't exist before the modal is shown. What is the recommended approach?

Here's a Plunkr with my current setup. Please see app.component.ts line 17.

mark
  • 1,953
  • 1
  • 24
  • 47

1 Answers1

1

You can subscribe to this event after calling .show() like this this.bsModalRef.content.listUpdates.subscribe({...})

Also, you can create a shared service and inject it in both components, and use this event instead of an internal event of modal.

IlyaSurmay
  • 2,283
  • 12
  • 20
  • Thanks! I didn't realize I would have access to `content` – mark Mar 14 '18 at 12:11
  • this.bsModalRef.content.updateFunction.subcribe is not a function.... I console content inside this.bsModalRef.content ( i found there is updateFuntion).... I am using angular 9.1.3....... I set up output() property correctly inside child component – Sras Jun 15 '20 at 13:41