In angular 6, We have two approaches to create the form.
- Model-driven
- 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. )