Is it possible to detect change in a variable?
I have the following:
@Input('name') name: string;
I would like to call a function whenever change is happened in this variable 'name'.
Is it possible?
I am solve this question using default Angular feature named OnChanges, very similar to OnInit.
https://stackoverflow.com/a/61720541/13514355
You can do it the following:
private _name = '';
@Input('name')
set name(name: string) {
this._name = name;
doSomeStuff();
}
get name(): string { return this._name; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With