Using Angular Services and HttpClient to retrieve data

Now you need to connect your CurrentWeather component to the OpenWeatherMap APIs. In the upcoming sections, we will go over the following steps to accomplish this goal:

  1. Create a new Angular Service
  2. Import HttpClientModule and inject it into the service
  3. Discover the OpenWeatherMap API

  1. Create a new interface that conforms to the shape of the API
  2. Write a get request
  3. Inject the new service into the CurrentWeather component
  4. Call the service from the init function of the CurrentWeather component
  5. Finally, map the API data to the local ICurrentWeather type using RxJS functions so that it can be consumed by your component

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.