You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been struggling with a case which is almost an exact copy of 835: same intention of combining router selectors with other selectors. Unfortunately, none of the tips mentioned there solve my problem, however I made a small discovery and I would hope for someone in the know to explain it to me what is exactly happening, please.
I am trying to combine the entities from a lazy-loaded admin feature, with the route params, to display the currently accessed user entity.
exportconstgetUserFromRouteParam=createSelector(selectEntities,// from entity adapterfromRouter.getRouterStateParams,(entities,params)=>{console.log(entities,params)returnentities[params['id']]})
This selector fails because of params being undefined. Alongside, there is a console warning saying that the feature name 'router' does not exist in the state (although it does exist)...
However when I bring this very selector directly into my component, like so:
I get a beautifully populated state, just as expected, and the warning is not there.
I would like to understand what is happening here.
Of course, as a workaround, I could combineLatest those two selectors in my component, but I would prefer to move it down to the ngrx selector layer (architecture, memoization) and rather understand how to make it work.
Why is it that a selector from router store doesn't work within another selector but does work on its own. Is it a race condition? What can I try?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have been struggling with a case which is almost an exact copy of 835: same intention of combining router selectors with other selectors. Unfortunately, none of the tips mentioned there solve my problem, however I made a small discovery and I would hope for someone in the know to explain it to me what is exactly happening, please.
I am trying to combine the entities from a lazy-loaded
admin
feature, with the route params, to display the currently accessed user entity.router.selectors
user.selectors.ts
This selector fails because of params being
undefined
. Alongside, there is a console warning saying that the feature name 'router' does not exist in the state (although it does exist)...However when I bring this very selector directly into my component, like so:
I get a beautifully populated state, just as expected, and the warning is not there.
I would like to understand what is happening here.
Of course, as a workaround, I could
combineLatest
those two selectors in my component, but I would prefer to move it down to the ngrx selector layer (architecture, memoization) and rather understand how to make it work.Why is it that a selector from router store doesn't work within another selector but does work on its own. Is it a race condition? What can I try?
Beta Was this translation helpful? Give feedback.
All reactions