'Minlength error in template driven form in angular 8
I am getting below error when i click the submit button.
ERROR TypeError: Cannot read property 'minlength' of null
I do not know why i am getting this error.So How to resolve this issue.
app.component.html:
<form name="form" (ngSubmit)="f.form.valid && onSubmit()" #f="ngForm" novalidate>
<div class="form-group">
<label for="categoryName">Category Name:</label>
<input type="text" class="form-control" name="categoryName" [(ngModel)]="cate.categoryName" minlength="5" #categoryname="ngModel" [ngClass]="{ 'is-invalid': f.submitted && categoryName.invalid }" required/>
<div *ngIf="f.submitted && categoryName.invalid" class="invalid-feedback">
<div *ngIf="categoryName.errors.required">
Category Name is required
</div>
</div>
<div *ngIf="categoryName?.touched && categoryName?.errors.minlength" class="invalid-feedback">
Category Name must be at least 5 characters long.
</div>
</div>
</form>
Solution 1:[1]
<div *ngIf="categoryName.touched && categoryName.errors?.['minlength']" ></div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahdi Zarei |
