I have 2 API calls for data fetching and 2 dispatch events for the data store in ngrx store.
The problem is When I call the first FETCH_FINANCIAL_INSTITUTION dispatcher and 2nd FETCH_USER_GROUPS dispatcher, institutions are removed. See the below screenshots.
See below my implementations,
For Institutes,
this.store.dispatch({ type: Action.FETCH_FINANCIAL_INSTITUTION, payload: <IFinancialInstitution[]> institutions, });For user groups,
this.store.dispatch({ type: Action.FETCH_USER_GROUPS, payload: <IUserGroup[]> userGroups, });
Here are the reducers,
Institute reducer
export interface IFinancialInstitutionState { institutes: IFinancialInstitution[]; } export class FinancialInstitutionState implements IFinancialInstitutionState { institutes: IFinancialInstitution[] = []; } export function FinancialInstitutionReducer( state: IFinancialInstitutionState = new FinancialInstitutionState(), action) { switch (action.type) { case Action.FETCH_FINANCIAL_INSTITUTION: return {...state, ...{institutes : action.payload}}; } }User group reducer
export interface IUserGroupState { userGroup: IUserGroup[]; } export class UserGroupState implements IUserGroupState { userGroup: IUserGroup[] = []; } export function UserGroupReducer ( state: IUserGroupState = new UserGroupState(), action, ) { switch (action.type) { case Action.FETCH_USER_GROUPS : return {...state, ...{userGroup : action.payload}}; } }
root reducer,
export const rootReduces = {
authData : AuthReducer,
usersData : UsersReducer,
systemData : SystemReducer,
institutesData : FinancialInstitutionReducer,
userGroupData : UserGroupReducer,
};
AppState.ts
export interface AppState {
readonly authData: IAuthResult[];
readonly usersData: UserState;
readonly systemData: SystemConfigs;
readonly institutesData: IFinancialInstitutionState;
readonly userGroupData: IUserGroupState;
}

