From the course: Learning NgRx

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Source code with comments

Solution: Source code with comments - Angular Tutorial

From the course: Learning NgRx

Start my 1-month free trial

Solution: Source code with comments

- [Instructor] Here is one possible solution to this third challenge. The first thing I did here, is that I created actions very similar to the ones we used for current conditions. One for the ForecastLoaded event, and one for ForecastLoadFailed. Both of these actions have the forecast as a payload of course and the zipcode in case of failure. Then I also created my own reducers for that. So when the forecast is loaded, we just change the state, and add the forecast to it. Note that we only have one forecast displayed at any given time in the application. So I just keep one object here, there's no array any more. Every time I get a new forecast, I'll just change the state with that specific forecast. Then of course how to wire up everything in the index.ts. I added the ForecastState to the GlobalState as well as my forecastReducer, down there on line 26 in the list of reducers. Once I have that, everything is pretty much ready. The final step was to create an effect. The effect is…

Contents