【发布时间】:2020-04-06 06:58:32
【问题描述】:
我有一个父子组件,我希望父组件能够在子组件中触发一个功能,同时也允许子组件在父组件中触发一个功能。以下是我为子级触发父级函数所做的工作:
孩子
@Output() callParentFunction = new EventEmitter<any>();
...
this.callParentFunction.emit();
父母
template: `
<child-component
(callParentFunction)="parentfunction($event)"
>
</child-component>
`
这可以触发parentfunction,但我该怎么做呢?我需要使用来自父级的事件发射器来触发子函数。
【问题讨论】:
标签: angular typescript components eventemitter