Trigger OnChanges by changing a property on a data-related object

How can I get ngOnChanges () to fire if a property on one of the data-related objects changes, instead of setting the property to a new object.

// component
@Input() myObj: ObjType;
// component code...

It does not cause a change

// outside component
dataBoundObj.width = 1000;

It does

dataBoundObj = new ObjType();
+4
source share
1 answer

Angular does not detect changes when the object is mutated. However, when checking the current component, it starts ngDoCheck. Thus, you can perform the check yourself and run ngOnChangesfrom there:

ngDoCheck() {
   if (this.o.width !== this.oldWidth) {
      this.ngOnChanges();
   }
}
+2
source

Source: https://habr.com/ru/post/1680535/


All Articles