How to get change event on input field for directive in angular 4

I'm a bit new to angular 4. I'm trying to get a change event from an input field inside a directive. I am currently working with @HostListener

@HostListener('keyup', ['$event'])
  inputChanged(event) {}

      

This works correctly, but this event is triggered after some delay after the key is released, and the user may enter incorrect input and may also see it. In my implementation, I removed the invalid input, but it doesn't give a good impact to the user. The only thing I want is to get the change event right at the moment of change in the input field (character / string enters or deletes both). The current HTML looks like this

<input type='text' class="form-control" placeHolder='hh:mm:ss' time-input [(ngModel)]="params.time" name="time"/>

      

PS. time-input is the name of the directive and in the directive I am trying to get an event change and I dont want to move any implementation to the controller or component.

+3


source to share


1 answer


Using



@HostListener('ngModelChange', ['$event'])

      

+6


source







All Articles