Now, let's connect the new service method to the input field:
- Update citySearch to inject the weatherService and subscribe to input changes:
src/app/city-search/city-search.component.ts...export class CitySearchComponent implements OnInit { search = new FormControl() constructor(private weatherService: WeatherService) {} ... ngOnInit() { this.search.valueChanges .subscribe(...) }
We are treating all input as string at this point. The user input can be a city, zip code or a city and country code, or zip code and country code separated by a comma. While city or zip code is required, country code is optional. We can use the String.split function to parse any potential comma separated input and then trim any whitespace ...