Setting it up

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:

  1. Create a model.
  2. Create an entity state based on the model.
  3. Create an entity adapter.
  4. Create the initial state.
  5. 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 ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.