NGRX Store selector without subscription

193 Views Asked by At

I'm using Angular (with typescript) and I'd like to retrieve a value from the NGRX store without using subscription. If I do like this:

this.store.select(selectCardNickname)

it returns an Observable and I need to subscribe to that to get the value. I know there is the async pipe which could do that, but I need this value inside my typescript component, not in the html, because when I get this value I have to call a service which is gonna call my backend (using this parameter as payload).

This is the selector:

export const selectCardNickname = createSelector(selectProdTypeTabs, (tabs) => tabs.settings.value.cardNickname);

What can I do to solve that?

1

There are 1 best solutions below

1
timdeschryver On

Using store.select will always create a subscription, there is no way to read the state using a synchronous method. You can also let the effect handle this, as shown in https://timdeschryver.dev/blog/start-using-ngrx-effects-for-this#using-a-selector