C
C
Coder3212016-11-28 23:45:13
Angular
Coder321, 2016-11-28 23:45:13

Passing an event from ng-content to parent component?

There is a parent component with ng-content inside. Other directives are inserted into ng-content. How to transfer an event to a parent directive from directives inside without applying (event) to a view?

<parent-component>
    <child-component></child-component>
    <child-component></child-component>
</parent-component>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Zuev, 2016-11-29
@Coder321

There are many recipes,
one of them is to inject the parent component into the child
https://plnkr.co/edit/y7tRG625BsNIRdmIaGrY?p=preview
More options you can find here https://angular.io/docs/ts/latest/cookbook/ compone...

V
Vitaly, 2016-11-28
@vitali1995

If I understand the question correctly, the recipe is:
@Output() event: EventEmitter
+
(event)="parentEvent()"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question