D
D
DavidJarr2019-02-16 01:42:27
JavaScript
DavidJarr, 2019-02-16 01:42:27

Why is there no validation in Angular 7?

I create a form in angular, I do validation like this

<input name="Name" #Name="ngModel" [(ngModel)]="service.formData.Name" 
            class="form-control" placeholder="Mission naming" required maxlength="100">

As far as I understand, after validation, the input should have `ng-invalid` and `ng-touched` , but they are not there, after compilation, the input code is
<input class="form-control" maxlength="100" name="Name" required="" ng-reflect-required="" ng-reflect-maxlength="100">

What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MitakoHir, 2019-02-17
@DavidJarr

Where is your validation? You declared an input and made a binding to the property of the component, and you already need to check the value inside the component.
The form will not be valid if there are more than 100 characters, and when the component is generated, the value is empty, which means all conditions are met.
Look here
https://angular.io/guide/form-validation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question