Creating users

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 ...

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.