Angular Getters and Setters on @Input() fields

Here is a handy cheat sheet… I kept forgetting the syntax of when an @input() decorator was used with a setter 🤦‍♂️

Getter

get allowDay(): boolean {
return this._allowDay;
}

Setter

@Input() set allowDay(value: boolean) {
this._allowDay = value;
this.updatePeriodTypes();
}

The cool thing is that when you set the value of the variable, you can trigger a function call as above 😎


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *