1 year ago

#251157

test-img

Ismar Begic

Angular - one input field can't have a value greater that the other input field

In an Angular App Input field 1 cant be lower than input 2
Input fields are binding with ngModel, I need a function and if the input field 1 is lower than input field 2 than I want to display null in the input fields.
These input fields give back a percentage of some funds, as you can see in the TypeScript file.

HTML File

//Input field 1

              <input 
              type="number" 
              class="form-control" 
              (ngModelChange)="getPerc($event)"
              [(ngModel)]="projectD.percentage" 
              id="inpt4" 
              maxlength="3"   
              [name]="'percentagePerLift' + i" 
              [value]="projectD.percentage"
              > 
              <span class="procent"> %</span>

//Input field 2
                <input
                type="number" 
                [(ngModel)]="projectD.percentage_ca" 
                class="form-control" 
                id="inpt4" 
                maxlength="3" 
                [value]="projectD.percentage_ca" 
                [name]="'percentageWithheld' + i"
                >
                <span class="procent"> %</span>

TypeScript File

getPerc(value){
        this.userData.map((data) => {
          data.month_span = data.month_span.map((month_span) => {
            month_span.articles = month_span.articles.map((article: any) => {
              const amount = article.Amount;
              const sameBelop = (amount/100)*value;
              const invoiced = amount - sameBelop;
              article.Arrears = sameBelop;
              article.Invoiced = invoiced;
              return article;
            });
            return month_span;
          });
          return data;
      });

      this.getTotalArr();
      this.getTotalInvoiced();
  }

html

angular

typescript

ngmodel

0 Answers

Your Answer

Accepted video resources