mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
committed by
Andrew Kushnir
parent
4948ab9ee5
commit
9f4b46796e
@@ -37,15 +37,12 @@ export class UniqueAlterEgoValidator implements AsyncValidator {
|
||||
]
|
||||
})
|
||||
export class UniqueAlterEgoValidatorDirective implements AsyncValidator {
|
||||
constructor(private heroesService: HeroesService) {}
|
||||
constructor(private validator: UniqueAlterEgoValidator) {}
|
||||
|
||||
validate(
|
||||
control: AbstractControl
|
||||
): Observable<ValidationErrors | null> {
|
||||
return this.heroesService.isAlterEgoTaken(control.value).pipe(
|
||||
map(isTaken => (isTaken ? { uniqueAlterEgo: true } : null)),
|
||||
catchError(() => of(null))
|
||||
);
|
||||
this.validator.validate(control);
|
||||
}
|
||||
}
|
||||
// #enddocregion async-validator-directive
|
||||
|
||||
Reference in New Issue
Block a user