how do I figure out which validator to give an error in form-control

Discussão em 'Angular' iniciado por evrei666, Março 11, 2025.

  1. evrei666

    evrei666 Guest

    In a component with an input, I pass an array of such objects for validation:

    export class ValidatorItem {
    validator: ValidatorFn;
    errorText: string;
    }


    in component:

    ngOnChanges(changes: SimpleChanges): void {
    if ('validators' in changes) {
    this.formModel = this.formBuilder.group({
    value: ['', Validators.compose(this.validators.map(v => v.validator))],
    });
    }
    }


    that is, I need to get an errorText message depending on which validator fell. How can i do this?

    Continue reading...

Compartilhe esta Página