In the following exercise we will build on the previous exercise (ex 06) and add interoperability with rxjs. We will:
- Create a service that uses
HttpClientto communicate with the server. - Practice
rxMethodin signal store - Connect the signal store to asyncronous services
- Copy the source and public folders, make sure not to copy the
node-modulesand.angularfolders which are auto-generated - run
npm ito create the dependencies - run the project
ng s
- Go to the server folder
- run
npm ito install dependencies - run
npm startto start the server - This starts a json server running in port 3000.
- Now you can run http restful commands to add, change, read, and delete posts
- Create a service
- Inject
HttpClientModule - Make sure to provide http in the
app.config.tsfile - Add methods for each of the following:
- Get all tasks
- Update a task
- Create a new task
- Delete a task
- Possible values: 'Idle', 'Loading'
- Add setters to set as loading, and set as idle
- Add a "reload" method that:
- sets load state as 'loading'
- calls 'Get all tasks' methods from the data service
- Flatten the observable using the proper operator
- add side effect that sets the current tasks in the store, and sets load state to idle
- Add an overlay with the Loading caption
- Place it on top of the UI
- Add
@ifso that it only appears when the UI is loading
- Implement the
addmethod using the service - Implement the
deletemethod using the service - Implement the
togglemethod using the service - Remember to set state to 'loading' at the begining of each action
- Remember to call
reloadat the end of each action.
In this exercise you practiced:
- Using RxJS observables and operators
- Working with HTTP
- Connecting Signals and RxJS using
rxMethod