I am adding dynamic components to div in angular using createComponent
method
let coolComponentRef = this.formControls?.createComponent(CoolComponent);
Child components site inside parent components and there are few events which i want to send to parent components.
I do this using @Output
on child component.
@Output()
propertiesEvent = new EventEmitter<Properties>();
and its usage is
<cool-component (propertiesEvent)="itemSelected($event)"></cool-component>
full example:
<div id="formControls" #formControls>
<cool-component (propertiesEvent)="itemSelected($event)"></cool-component>
</div>
However, my use case is that the child elements are added dynamically using createComponent
, so how can i add (propertiesEvent)
to dynamically created component.
EDIT: Found this link usefull Angular4 communication between child dynamically created component to parent, is there other simpler way exists?