
Member-only story
NgRx/Store
A quick tutorial on working with data in an Angular application
Angular is a framework for creating the front-end for web applications. However, it is purely geared toward creating visual components, not for handling domain data. That’s where NgRx comes in. It’s a library for working with data on the front end in a “Flux” pattern, which is a slight variant of MVC (I like this explanation of it: Flux vs MVC). All modern web frameworks have a typical library like this for handling data. For React, the library is Redux. For Vue, it’s Vuex.
Some quick terminology:
- store: a javascript object that holds your data
- state: the store’s data at a given point in time
- slice: a property of your store (so just a section of your overall data)
- reducer: a pure function for altering your state
- action: a key and some values used to tell the reducer what slice of state you want to change
- dispatch(): a method used to run actions
- subscribe(): a method used to detect state changes
In a nutshell, using NgRx will look like this:
- import the store at root
- create a reducer for defining and changing state
- import the store and any reducers in your component
- use your reducer by dispatching actions to it
- subscribe to the store to detect when data is changed

What This Tutorial Covers
- Installation / Set Up
- Reducers & Actions
- Dispatching Actions
- Subscribing
- Testing
What You Need For This Tutorial