Parent Component
=====================
(notify) = “handler()”
==================
Child Component
@Output
notify
===================
If you want to pass some data from child to parent component, we create an EventEmitter and decorate with @Output() decorator to be communicated to the parent.
The Parent will have an event binding with the name of the eventEmitter bound to a method to receive the event from the child.
child.component.html
<button click=”passDataToParent()” >Emit Data </button>
import {Component, EventEmitter, Output} from ‘@angular/core
child.component.ts
export class ChildComponent{
@Output
noitfyParent:EventEmitter<string> = new EventEmitter<string>();
passDataToParent(){
this.notifyParent.emit(“”);
}
parent.component.html
<app-child (noitfyParent)=”parentMethod($event)” />
parent.component.ts
export class ParentComponent{
childData:string;
parentMethod(data){
this.childData = data;
}
}