Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...