Angular
Building a CRUD Application with Angular & ASP.Net Core - Services in Angular POST

Adding the POST request to our service

PRO

Adding the POST request to our service

In this video, we added our POST request to our service. We connected the HTML we created before to our component, then called our service from the component. The service makes the HTTP request to our API, which then addds the item to our database.

We now have the abilty to add new items to our database through our API! But like we saw in the video our camp list is not automatically updating. Right now we have to make another GET request before we have the data. We refreshed the page to simulate a GET request and that worked as well. This behavior would never work in a production app.

In the next video, we will be looking at how we can have our UI update automatically. How we can take control of what the user sees.

Observables are Lazy

Remember in the video, how at first our POST was not getting executed. This is because Observables are Lazy. No they don't sit on the couch watching TV all day. What this means is that they will not execute until they need to.

Because we were not subscribing to our POST request our observable thought we did not actually need the data. So it is important to remember that our HTTP requests must be subscribed to somewhere if we want them to actually be executed.