Home:ALL Converter>How to add validation in template driven form from component in angular 6

How to add validation in template driven form from component in angular 6

Ask Time:2018-08-17T22:33:54         Author:Nimish goel

Json Formatter

In angular 6, We have two approaches to create the form.

  1. Model-driven
  2. Template-driven

In the model-driven approach, we defined the validators via code in the component. And In the template-driven approach, we define the validators via directives and HTML5 attributes in our template itself.

Is there any approach, In the template-driven form, We can define the validation from component code.

I need to define and change the validation of a text box from component code on some input test change.

<input type="text" [(ngModel)]="value" (input)="ValueChangeEvent(myvalue)" /> 

Here, in the ValueChangeEvent method, I need to change the validation of my textbox.(For example, when user type something, then only I need to add the minimum value validation in the text box. )

Author:Nimish goel,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51897650/how-to-add-validation-in-template-driven-form-from-component-in-angular-6
yy