In HTML I have a (change)="limitUser($event)" function. In typescript I have a for loop which runs through each element and checks if the value is less than 10. If it exceeds 10 it sets the inValid = true.
In HTMl all my form fields set the value as true. I want only the form field with value greater than 10 to be set as true.
HTML Code:
<div *ngFor="p of data; let i = index">
<label>p.name{{i}}</label>
<input type="text" class="form-control" (change)="limitUser($event)" name="p.name{{i}}" [(ngModel)]="p.usage" id="p.name">
<div class="danger" *ngIf="inValid">
Please enter number smaller than 10
</div>
</div>
In typescript:
limitUser(event){
for (let i = 0; i < this.data.length; i ++) {
if (this.data[i].usage = 0 || this.data[i].usage = null || this.data[i].usage = ""){
this.data[i].usage = 0;
}
if (this.data[i].usage > 10){
this.inValid = true;
}
But inValid = true is applied to all the dynamic form fields. How can I put it only on the field whose value is larger than 10.
inputare missing closing quotes.