import { AbstractControl , AsyncValidatorFn } from '@angular/forms' ; import { CoursesService } from '../services/courses.service' ; import { map } from 'rxjs/operators' ; export function courseTitleValidator ( courses ) { return ( control ) => { return courses . findAllCourses ( ) . pipe ( map ( courses => { const course = courses . find ( course => course . description . toLowerCase ( ) == control . value . toLowerCase ( ) ) ; return course ? { titleExists : true } : null ; } ) ) ; } ; }