To be able to use the getCurrentWeather function in the CurrentWeather component, you need to inject the service into the component:
- Inject the WeatherService into the constructor of the CurrentWeatherComponent class
- Remove the existing code that created the dummy data in the constructor:
src/app/current-weather/current-weather.component.tsconstructor(private weatherService: WeatherService) { }
- Call the getCurrentWeather function inside the ngOnInit function:
src/app/current-weather/current-weather.component.tsngOnInit() { this.weatherService.getCurrentWeather('Bethesda', 'US') .subscribe((data) => this.current = data)}
Fair warning, do not expect this code to be working just yet. You should see ...