TodoListService, a service solely responsible for todo list item management, the only place where we have to make any code changes is inside that service.
HttpClientModulewhich offers a simplified HTTP client library. This module contains libraries we need to make the HTTP calls we'll use to interact with the server.
app.module.tsso that it's available for use within the application.
todo-list.service.ts. We'll ask for an instance of the
HttpClientservice in the constructor, and make sure to import the class.
addItemmethod we want to add the code to POST an item by using
HttpClient's built in
postmethod requires 2 parameters, the url and the body. Let's start with the url.
HttpClientknows where to POST the data. The url includes a host and a path. Since we are running the server locally, the server's host address is "localhost:3000".
HttpClientlibrary requires us to subscribe to the output of the
post()call to trigger calling the server. We can do so by adding
.subscribe()at the end of call.