Is there a way to listen for @Input change?
In following example, I would like to be informed whenever 'inputData' value is changed.
@Input() inputData: InputData;
Is there a way to listen for @Input change?
In following example, I would like to be informed whenever 'inputData' value is changed.
@Input() inputData: InputData;
 
    
    Yeah, you can use OnChanges lifecycle event:
@Input() inputData: InputData;
ngOnChanges() {
    console.log(this.inputData);
}
Read more about Angular's lifecycle events here.
 
    
    import { Component, Input, OnChanges, SimpleChange } from '@angular/core';
export class Demo implements OnChanges {
 @Input() inputData: InputData;
 ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
    if (changes['inputData'] && this.inputData) {
        //your logic work when input change
    }
 }
}
 
    
    you can use something like :
Input('value')
set value(val: string) {
  this._value = val;
  console.log('new value:', value); // <-- do your logic here!
}
more info available at this link
you can also take a look at this article
 
    
     
    
    You could listen to OnChanges component lifecycle event inside your component
ngOnChanges(model: SimpleChanges){
   console.log(model)
}
