user3428422
user3428422

Reputation: 4560

How to use the value from an RxJS observable subscribe call

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.

enter image description here

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)

enter image description here

enter image description here

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

enter image description here enter image description here

This now takes the new value.

Thanks

Upvotes: 1

Views: 318

Answers (1)

Hojjat Bakhtiyari
Hojjat Bakhtiyari

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

Related Questions