Search⌘ K
AI Features

Handling the Response

Understand how to integrate a service into an Angular custom validator to check for compromised passwords. Learn to convert functions for proper scope, manage observables, and handle API errors with RxJS operators to ensure accurate validation results.

We'll cover the following...

Our service is ready. It’s time to load it in the validator so that we can use it.

Using the service

In the compromised-password.ts file, we’ll import the service and inject it into the validator.

TypeScript 3.3.4
import { AsyncValidator, FormControl } from '@angular/forms';
import { EnzoicService } from '../enzoic.service';
export class CompromisedPassword implements AsyncValidator {
constructor(private enzoic: EnzoicService) { }
validate = (control: FormControl) => {
return this.enzoic.checkPassword(control.value);
}
}

In the example above, we’re injecting the service into the validator. Then, we’re converting the validate function into an arrow function because validators are passed in as ...