Search code examples
ngrxngrx-entity

Addtional parameter with @ngrx/entity


I want to keep employee array and page loading status in store state. So my initial state will look like this

const initialState = {
  isLoading: false,
  employees: []
  };

Now i want to use @ngrx/entity for employee instead of array. The documentation only show the demo for using entity with entire state.

How can i use entity for only one property rather than entire state?

If it's not possible what is the alternative for above scenario?


Solution

  • See the docs for an example:

    import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
    
    export interface User {
      id: string;
      name: string;
    }
    
    export interface State extends EntityState<User> {
      // additional entities state properties
      selectedUserId: number;
    }
    
    export const adapter: EntityAdapter<User> = createEntityAdapter<User>();