I need to detect value changes in @Input
binding angular and execute a function when the value is changed
@Component({
selector: 'my-comp',
...
})
...
@Input() myValue
//detect myValue changes
<my-comp [myValue]= "val"></my-comp>
I need to execute some code component class when val
changes.
You could simply use set
here, like this:
_myvalue: any;
@Input() set myValue(value: any) {
... // Your code goes here
this._myvalue = value;
}
Now, everytime you assign a value to myValue
inside your template the setter is called and your code will be executed.
I hope that helps!
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