code into child component mycomponent.ts
import { Component, OnInit , EventEmitter, Output } from \'@angular/core\';
@Component({
selector: \'app-mycomponent\
The Childcomponent emits a click event. The click event of your childcomponent is emitting a String, as you defined here:
@Output() clicked = new EventEmitter();
clickchild() {
this.clicked.emit('This is Child Component Code!');
}
The payload of the event (a string in this case), can then be accessed by the parameter $event. You subscribe in your parent component to the click event by:
onClicked(value: string) {
this.childdata = value;
}
So the child component emits a click event, but it has to be recognized by the parent component (utilizing subscription), otherwise the parent would not know about the emitted event.
See here for the docs: https://angular.io/api/core/EventEmitter
Sagat