Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call an event in parent component from child component which is loaded using DCL loadintolocation()

Tags:

angular

I have an event in parent component. I want to call that event from the a child component created using DCL loadintolocation(). I am following this logic in the child component to raise the event

@Output() myevent1: EventEmitter;
onSubmit() {
  console.log(this.myForm.value);
  this.myevent1.emit();
}

I am able to raise the events for components which are already mentioned but not to components that are created using DCL. Please tell me how to raise the event in parent component from components created dynamically.

Here is the plunker demo i have worked till now http://plnkr.co/edit/2LJL4HxSc74XAyGmQMio?p=preview

like image 548
abhilash reddy Avatar asked Feb 08 '23 20:02

abhilash reddy


1 Answers

When you load the component, you can subscsribe to the event of the child from where you can call the parent function.

dcl.loadIntoLocation(ChildComponent, elementRef, 'child')
  .then((newComponent) => {
    newComponent.instance.event.subscribe(() => { .. call your parent ..});
  })

UPDATE

see the plunker here: http://plnkr.co/edit/DNmtl6TG5s2dsEUlVTvw?p=preview

like image 67
eesdil Avatar answered Feb 11 '23 16:02

eesdil