Reputation: 12189
How can I get ngOnChanges() to trigger if a property on one of the data bound objects changes rather than having to set the property to a new object.
// component
@Input() myObj: ObjType;
// component code...
This doesn't trigger the change
// outside component
dataBoundObj.width = 1000;
This does
dataBoundObj = new ObjType();
Upvotes: 6
Views: 2451
Reputation: 105517
Angular doesn't detect change when you mutate an object. However, it triggers ngDoCheck
when checking current component. So you can perform a check yourself and trigger ngOnChanges
from there:
ngDoCheck() {
if (this.o.width !== this.oldWidth) {
this.ngOnChanges();
}
}
Upvotes: 3