Search code examples
angularformstextonchangeinput-field

Angular 10 (change) not detected on form inputfield


When I use the (change) to detect inputfield changes it only shows me changes when the user leaves the inputfield. this is the html code :

<input type="text"  (change)="check('test')" class="form-control form-control-lg" class="form-control" formControlName="title"  [ngClass]="!rForm.controls['title'].valid && rForm.controls['title'].touched ? 'red-border-class' : 'black-border-class'">

What am I doing wrong I want to detect a change immediately not after the user goes to the next inputfield.

Someone who can help?

Thx


Solution

  • Use Keyup instead of Change may be it would suit your requirement

    <input type="text"  (keyup)="check('test')" class="form-control form-control-lg" class="form-control" formControlName="title" 
          [ngClass]="!rForm.controls['title'].valid && rForm.controls['title'].touched ? 'red-border-class' : 'black-border-class'">