When working with Angular 6, there are two main approaches for creating forms:
- The Model-driven approach
- The Template-driven approach
In the Model-driven approach, validators are defined within the component code. On the other hand, in the Template-driven approach, validators are defined using directives and HTML5 attributes directly in the template.
Is it possible to define validation from the component code in a Template-driven form?
I have a requirement where I need to dynamically change the validation of a text box based on user input.
<input type="text" [(ngModel)]="value" (input)="ValueChangeEvent(myvalue)" />
Here, in the ValueChangeEvent
method, I want to modify the validation rules of the textbox. For example, adding minimum value validation only when the user enter some input.