From the course: Angular State Management with NgRx

Unlock this course with a free trial

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

Solution: Create your first SignalStore

Solution: Create your first SignalStore - Angular Tutorial

From the course: Angular State Management with NgRx

Solution: Create your first SignalStore

(upbeat music) - [Instructor] So here is one possible solution for code challenge. I created a new file, current-conditions.store.ts in which we created our default state and the type for that state. So it's a Record that's going to map a string, which is really our zipcode, to the current conditions. The initial state is empty, we don't have any data by default. And then we use the signalStore function from NGRX Store to create our signalStore. It's going to be a service provided in root. It's going to use our initialState by default. And we really want two methods in here. We want a method to add a zipcode, and one to remove a zipcode. So when we add a zipcode, it's going to be asynchronous because we have to make a call to the API. So we use rxMethod, and in that rxMethod we basically turn our asynchronous work into a request, into an API request, using weatherService. And once we get the result from that, we are going to pipe it and use a tap operator to listen to updates and…

Contents