Reputation: 4560
I have a subject
that passes in an object from another component. in the subscribe, I assign what has been passed into a class property.
I then want to use this property to help me reload an ag-Grid
which helps with the styling. However, if I call it after the value has been assigned in the asynchronous subscribe call, it uses the previous value of this.ViewContext
.
I have even purposely set it in the complete call but this doesn't work neither.
However, if I call it on a button click afterwards the subscribe call, it works... (or gets the last value passed into by the subject)
Is there any way I can do this without a further event (like the button click?)
-------------- The Answer ------------
Based on the answer below, this is the change in code
This now takes the new value.
Thanks
Upvotes: 1
Views: 318
Reputation: 187
I think, your problem is related to change detection. You should inject 'private cdr: ChangeDetectorRef' in your component. then call cdr.detectChanges() when your value is updated.
Upvotes: 1