Implementing an HTTP GET operation

Now, we can implement the GET call in the Weather service:

  1. Add a new function to the WeatherService class named getCurrentWeather
  2. Import the environment object
  3. Implement the httpClient.get function

  1. Return the results of the HTTP call:
src/app/weather/weather.service.tsimport { environment } from '../../environments/environment'...export class WeatherService {  constructor(private httpClient: HttpClient) { }  getCurrentWeather(city: string, country: string) {    return this.httpClient.get<ICurrentWeatherData>(        `${environment.baseUrl}api.openweathermap.org/data/2.5/weather?` +          `q=${city},${country}&appid=${environment.appId}`    )  }}
Note the use of ES2015's String Interpolation feature. Instead of building ...

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.