Mark Timothy
Mark Timothy

Reputation: 1814

How to listen for child event from parent directive in Angular2

I have a child component 'my-component' which is wrapped by a Directive 'MyDirective' , I need to emit an event to parent directive from the child component, I know how to do it for parent component using @Output but no luck with directive.

<div myDirective >
    <my-component></my-component>
</div>

Any idea?

Upvotes: 0

Views: 2968

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657666

One approach is to use a template variable and reference it in an event handler:

<div myDirective #mydir>
    <my-component (someEvent)="mydir.someMethod()"></my-component>
</div>

Upvotes: 3

Related Questions