ngOnChanges
ngOnChanges ngOnChanges is a lifecycle hook that is triggered whenever an @Input() property changes, including before the component is rendered the first time. Common Use Cases: React to Input Changes : Fetch data, recalculate values, or run logic when an input changes. Reset Internal State : Clear or update internal variables based on new inputs. Track Previous vs Current Values : Useful for logs or conditional operations. Conditional API Calls : Trigger HTTP or DOM updates when inputs meet criteria. Cascading Dropdowns : Update dependent data like states based on selected country. Example: Parent Component: userName = 'John'; changeName() { this.userName = 'Jane'; } Child Component: @Input() name!: string; ngOnChanges(changes: SimpleChanges) { const change = changes['name']; console.log(`Name changed from ${change.previousValue} to ${chan...