Facing issue in updating selected user state in angular using ngrx

给你一囗甜甜゛ 提交于 2019-12-24 16:53:31

问题


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 the selectedUserId and the users 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!