city-edit.component.ts

The first thing we have to do is create the validator itself and bind it to our Reactive Form. To do that, open the /ClientApp/src/app/cities/city-edit.component.ts file and change its contents accordingly (the new/updated lines are highlighted):

import { Component, Inject } from '@angular/core';import { HttpClient, HttpParams } from '@angular/common/http';import { ActivatedRoute, Router } from '@angular/router';import { FormGroup, FormControl, Validators, AbstractControl, AsyncValidatorFn } from '@angular/forms';import { Observable } from 'rxjs';import { map } from 'rxjs/operators';import { City } from './City';import { Country } from './../countries/Country';// ...existing code...  ngOnInit() { this.form = new FormGroup({ ...

Get ASP.NET Core 3 and Angular 9 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.