Search⌘ K
AI Features

Setting Up the Actions with Action Creators

Explore how to set up NgRx actions with action creators in Angular. Understand how to define action types and payloads using createAction to efficiently retrieve data from a mock server and optimize state management. This lesson helps you reduce redundant HTTP calls by storing and accessing data through the NgRx store.

In this lesson, we’ll configure an action to retrieve all products from the mock server.

Introduction to NgRx actions

The action represents a specific event that can occur in our application. Each action has a required type property that identifies the type of event that occurred. For example, in the Products component of our application, we might have an action that represents fetching data from the database. In this case, the type property would be set to [Products] Get Products. The convention is to write the type property as [Module Name] Action Name. Actions can also have an optional payload property that contains the ...