As we can see, EntityStateAdapter has methods for the full CRUD. Let's look at adding the capability to add a user to our component. We need to make the following additions to our component:
- Add an input field
- Dispatch an ADD_USER action with our new user as payload
The required code changes are in bold, as follows:
// app.component.ts - adding the capability to add usersimport { Component } from "@angular/core";import { AppState } from "./app-state";import { Store } from "@ngrx/store";import { map } from "rxjs/operators";@Component({selector: "app-root",template: ` <div style="border: solid 1px black; padding: 10px;" *ngFor="let user of users$ | async"> {{ user.name }} </div> <div> <input [(ngModel)]="user" /> <button ...