How to listen to events in the parent element, emitted from entryComponents?

1.3K    Asked by WandaMay in Python , Asked on Feb 5, 2020
Answered by Wanda May

A component injected through entryComponents will instantiate it yourself, then we can simply keep a reference on it and subscribe to the public EventEmitter.

After creating our ComponentPortal we attached it to a PortalOutlet or an OverlayRef. The return value of attach contains the instance of the injected component.

For example, let's say our component is named SomeComponent and has an EventEmitter named someEventEmitter:

let portal = new ComponentPortal(componentFactory.componentType);

let component = overlayRef.attach(portal);

component.instance.someEventEmitter.subscribe(() => {

  //Some code

});



Your Answer

Interviews

Parent Categories