Implementing search

Now, let's connect the new service method to the input field:

  1. 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 ...

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.