Angular

Last Updated: 7/10/2023

Output Properties

  • Component can raise custom event, so that we can bind to the method in host component and get notified
<favorite (change)="onFavoriteChanged()">
onFavoriteChanged() {
	console.log("favorite changed");
}
  • Import Output, EventEmitter from angular
import {Output, EventEmitter} from '@angular/core';
  • Add output decorator and initialize to event emitter
  • The name of the field should be same as the event we want to raise
@Output() change = new EventEmitter();

Raise event

  • We use emit to raise or publish an event, notify others that something has happen
onClick(){
	this.change.emit();
}