I have an angular component which has an input Person
export class Person {
public name = 'Initial Name';
}
export class PersonComponent implements OnInit, OnChanges {
@Input() public person: Person;
ngOnChanges(changes: SimpleChanges): void {
console.log('changed');
}
}
In the parent component of this component, if I replace the Person object which is given as the input to the child component, ngOnChanges() gets fired in the child component.
But, if I only change the name of the Person object from the parent component, ngOnChanges() doesn't get fired in the child component (anyway, if I bind the person name to an html element in the child template, it gets updated).
Is there any way to get notified in the child component when a property of an input is changed?