How to trigger Angular 2 input validation manually?

后端 未结 3 1334
萌比男神i
萌比男神i 2021-02-01 13:06

I have two inputs: - First one on which I apply my custom validator - Second one which value I use in my custom validator (it is dynamic and editable)

If I apply my cust

3条回答
  •  日久生厌
    2021-02-01 14:06

    If you have template-driven form you can access form throw ViewChild decorator:

    @ViewChild('myForm') public form: NgForm;
    

    then, validate one field or the whole form group using method mentioned above:

    this.form.controls.myControl.updateValueAndValidity();
    

提交回复
热议问题