问题
Hi guys i am new to ngrx in angular. I am showing a list of users and given a view button based on view click i want to display user info of only selected latest one. I am using ngrx for this but what happens it merge the new selected with existing one but i want latest one below is my stackbiltz link. Please check and let me know how can i modify it
回答1:
The problem isn't the reducer, but how the state is structured.
@ngrx/entity
keeps a collection of loaded entities, it isn't fitted for a single entity imho.
You have two options:
- only store one used in the state, instead of a collection
- keep track of the selected user, this can be done by setting a
selectedUserId
in the store state and by creating a selector which will select the selected user based on theselectedUserId
and theusers
in the state. See the example-app for an example.
来源:https://stackoverflow.com/questions/58496527/facing-issue-in-updating-selected-user-state-in-angular-using-ngrx