When I make a change to a property of an object, Angular's default change detection is not working:
@Component({
selector: 'parent-comp',
template: `<child-comp [mutableObject]="mutableObject"></child-comp>`
})
export class ParentComp implements OnInit {
mutableObject: MutableObject = { someProp: 'hello' };
onClickedSomething() {
this.mutableObject.someProp = 'goodbye';
}
}
@Component({
selector: 'child-comp',
template: `<h1>{{ mutableObject.someProp }}</h1>`
})
export class ChildComp implements OnInit, OnChanges {
@Input() mutableObject: MutableObject;
ngOnInit() {}
ngOnChanges(changes: SimpleChanges) {
console.log('change detected');
}
}
ngOnInit gets called in child component the first time both parent and child components load, but when onClickedSomething() method changes the property value, the child component doesn't detect the change. I made sure that ChangeDetectionStrategy.OnPush is not being used. What could be going wrong here?