[英]How to get change event in input field for a directive in angular 4
I am a bit new to angular 4. I am trying to get change event from an input field inside a directive. 我对angular 4有点新。我试图从指令内的输入字段获取更改事件。 Currently i am working with @HostListener 目前我正在使用@HostListener
@HostListener('keyup', ['$event'])
inputChanged(event) {}
This is working correctly but this event is fired after some delay from releasing key and user can enter wrong input and is able to see that too. 这是正常的,但是这个事件在释放密钥一段时间后触发,用户可以输入错误的输入并且也可以看到。 In my implementation i have removed the invalid input but it doesn't give a good exposure to user. 在我的实现中,我删除了无效输入,但它没有给用户良好的曝光。 Only thing i want is to get change event right the moment change happen in input field (character / string enter or remove both ). 我唯一想要的就是在输入字段中发生更改时获得更改事件(字符/字符串输入或删除两者)。 Current HTML looks like this 当前的HTML看起来像这样
<input type='text' class="form-control" placeHolder='hh:mm:ss' time-input [(ngModel)]="params.time" name="time"/>
PS. PS。 time-input is the name of directive and in directive i am trying to get the event change and i don't want to move any implementation to controller or component. time-input是指令的名称,在指令中我试图让事件发生变化,我不想将任何实现移动到控制器或组件。
使用
@HostListener('ngModelChange', ['$event'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.