mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs: update NG_VALIDATORS examples to use forwardRef (#63247)
PR Close #63247
This commit is contained in:
parent
2aa9775078
commit
6a6cb01bb3
5 changed files with 22 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// #docregion
|
||||
import {Directive, input} from '@angular/core';
|
||||
import {Directive, forwardRef, input} from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
NG_VALIDATORS,
|
||||
|
|
@ -22,7 +22,13 @@ export function forbiddenNameValidator(nameRe: RegExp): ValidatorFn {
|
|||
@Directive({
|
||||
selector: '[appForbiddenName]',
|
||||
// #docregion directive-providers
|
||||
providers: [{provide: NG_VALIDATORS, useExisting: ForbiddenValidatorDirective, multi: true}],
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALIDATORS,
|
||||
useExisting: forwardRef(() => ForbiddenValidatorDirective),
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class ForbiddenValidatorDirective implements Validator {
|
||||
forbiddenName = input<string>('', {alias: 'appForbiddenName'});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// #docregion
|
||||
import {Directive} from '@angular/core';
|
||||
import {Directive, forwardRef} from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
NG_VALIDATORS,
|
||||
|
|
@ -24,7 +24,11 @@ export const unambiguousRoleValidator: ValidatorFn = (
|
|||
@Directive({
|
||||
selector: '[appUnambiguousRole]',
|
||||
providers: [
|
||||
{provide: NG_VALIDATORS, useExisting: UnambiguousRoleValidatorDirective, multi: true},
|
||||
{
|
||||
provide: NG_VALIDATORS,
|
||||
useExisting: forwardRef(() => UnambiguousRoleValidatorDirective),
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class UnambiguousRoleValidatorDirective implements Validator {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// #docregion
|
||||
import {Directive} from '@angular/core';
|
||||
import {Directive, forwardRef} from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
NG_VALIDATORS,
|
||||
|
|
@ -24,7 +24,11 @@ export const unambiguousRoleValidator: ValidatorFn = (
|
|||
@Directive({
|
||||
selector: '[appUnambiguousRole]',
|
||||
providers: [
|
||||
{provide: NG_VALIDATORS, useExisting: UnambiguousRoleValidatorDirective, multi: true},
|
||||
{
|
||||
provide: NG_VALIDATORS,
|
||||
useExisting: forwardRef(() => UnambiguousRoleValidatorDirective),
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class UnambiguousRoleValidatorDirective implements Validator {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ export type ValidationErrors = {
|
|||
* ```ts
|
||||
* @Directive({
|
||||
* selector: '[customValidator]',
|
||||
* providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
|
||||
* providers: [{provide: NG_VALIDATORS, useExisting: forwardRef(() => CustomValidatorDirective), multi: true}]
|
||||
* })
|
||||
* class CustomValidatorDirective implements Validator {
|
||||
* validate(control: AbstractControl): ValidationErrors|null {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ function lengthOrSize(value: unknown): number | null {
|
|||
* ```ts
|
||||
* @Directive({
|
||||
* selector: '[customValidator]',
|
||||
* providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
|
||||
* providers: [{provide: NG_VALIDATORS, useExisting: forwardRef(() => CustomValidatorDirective), multi: true}]
|
||||
* })
|
||||
* class CustomValidatorDirective implements Validator {
|
||||
* validate(control: AbstractControl): ValidationErrors | null {
|
||||
|
|
|
|||
Loading…
Reference in a new issue