We start by downloading the entity library. To do this, we need to run the following command:
npm install @ngrx/entity
We then need to perform the following steps:
- Create a model.
- Create an entity state based on the model.
- Create an entity adapter.
- Create the initial state.
- Create the reducer and set up the state in the StoreModule.
Let's start off by creating our model:
// user.model.tsexport interface User { id: number; name: string;}
The preceding code is just a simple model with fields id and name. We then create our entity state, like so:
// excerpt from app.module.tsimport { EntityState, createEntityAdapter, EntityAdapter } from "@ngrx/entity";export interface State extends EntityState<User> { selectedUserId ...