如何从使用DCL loadintolocation()加载的子组件中调用父组件中的事件 [英] How to call an event in parent component from child component which is loaded using DCL loadintolocation()
问题描述
我在父组件中有一个事件.我想从使用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();
}
我能够引发已经提到的组件的事件,但是不会引发使用DCL创建的组件的事件.请告诉我如何从动态创建的组件中引发父组件中的事件.
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.
这是我到目前为止一直在工作的插件演示 http://plnkr.co/edit/2LJL4HxSc74XAyGmQMio?p =预览
Here is the plunker demo i have worked till now http://plnkr.co/edit/2LJL4HxSc74XAyGmQMio?p=preview
推荐答案
在加载组件时,您可以订阅子事件,从那里可以调用父函数.
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 ..});
})
更新
在此处查看"punker": http://plnkr.co/edit/DNmtl6TG5s2dsEUlVTvw?p=preview
see the plunker here: http://plnkr.co/edit/DNmtl6TG5s2dsEUlVTvw?p=preview
这篇关于如何从使用DCL loadintolocation()加载的子组件中调用父组件中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!