From the course: Angular: Building Large Applications

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Setting up NgRx with actions, reducers, and effects

Setting up NgRx with actions, reducers, and effects - Angular Tutorial

From the course: Angular: Building Large Applications

Setting up NgRx with actions, reducers, and effects

- [Instructor] Let's take a look at code examples for the state. So, go into the Exercise Files, chapter two and 02_05 and open these files. So, I'm just going to drop my folder here. So, let's first take a look at actions. Actions in NgRx define events that trigger changes in the state. Each action has a type, an optional payload. You have, in this case, loadProducts, so this action starts the process of loading products. It's dispatched when the app needs to fetch product data. The loadProductsSuccess is when this action is dispatched when the products are successfully loaded. It carries the list of products, which will be added to the state. And then finally, you have loadProductsFailure. So, this action is dispatched if there's an error during the product loading process. It carries the error information, which the state can use to display an error message to the user. Then you have the effects. Effects in NgRx manage side effects like making API calls or performing async…

Contents