#Input variable changes but doesn't trigger ngOnChanges?

3 messages · Page 1 of 1 (latest)

oblique gorge
#

Hello, I have made a component in an angular library.
This component has an @Input() that refers to a variable in the applications app.component.ts

<app-viewer
            id="viewer"
            [selectedProject]="selectedProject"
            [config]="viewerConfig"
            [selections]="viewerSelections"
></app-viewer>

In the the viewer component then implements the OnChanges interface and when I update the viewerSelections variable in the app.component
there is no triggering of the ngOnChanges method. Something has to be wrong here because I know this isn't how it's supposed to work.

viewerSelections: ViewerSelections = this._appState.viewerSelections.getValue();

I initiate the value in the app.component like so, but updates to it is done in other subscriber methods and can happen anytime.
What can be the reason behind not trigger ngOnChanges? I have tried to refactor it several times but without success and its incredibly frustrating.

I use angular 15.1.4

#

Seems like the issue was that it actually didn't change because when I did:
this.viewerSelections = Object.assign({}, e);

It solves the issue so apparently it was passing by reference. Funny that I solved it a minute posting after hours of trying...

worthy steppe
#

lol