Skip to content

Instantly share code, notes, and snippets.

@Burgov
Last active August 7, 2022 18:27
Show Gist options
  • Save Burgov/c83d88075792bac7832d1d063bb0bb83 to your computer and use it in GitHub Desktop.
Save Burgov/c83d88075792bac7832d1d063bb0bb83 to your computer and use it in GitHub Desktop.
@Component({
selector: 'parent-component',
template: '<child-component [myInput]="myData" (myOutput)="handleEvent($event)"></child-component>'
})
export class ParentComponent {
protected myData = 'my data';
handleEvent(counter: number) {
alert(counter);
}
}
@Component({
selector: 'child-component',
template: '<div (click)="emitCounter()">{{ myData }}</div>'
})
export class ChildComponent {
@Input() myInput!: string;
@Output() myOutput = new EventEmitter<number>();
private counter = 0;
emitCounter() {
this.myOutput.emit(++counter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment