Handling the Response
In this lesson, we'll handle the response from the API.
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.
Press + to interact
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 references. When we pass in a reference, the scope of the function is not bound to the object. If we want to reset the scope, we’ll need to adjust the function into an arrow function. This will give us access to the this
keyword, which we’ll need if we want to use the service injected into the ...