简体   繁体   English

如何在角度为4的指令的输入字段中获取更改事件

[英]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.

相关问题 如何从angular2中的指令检测输入字段的模型变化 - How to detect change in model for input field from directive in angular2 Angular 2隐藏指令不会在输入字段更改时更新 - Angular 2 Hidden directive not updating on input field change 如何在 formControl 指令获取 angular 之前更改输入值 - how to change value of input before formControl directive get it in angular 如何通过angular 2中的事件对象获取输入字段名称 - how to get input field name through event object in angular 2 如何通过 Angular 7 中的自定义 angular 指令更改 html 输入标签名称? - How to change html input label name by custom angular directive in Angular 7? 如何测试对输入字段中的 keydown 事件做出反应的指令 - How do I test a Directive that reacts to keydown Event in an Input field 如何使用指令将事件添加到Angular 5应用程序中的输入? - How to add event to input in Angular 5 app using directive? 如何使用 Angular 5 中的按键事件为输入文本定义指令? - How to define directive for input text with the keypress event in Angular 5? 如何使用angular-2中的输入字段创建自定义指令? - How to make a custom directive with input field in angular-2? Angular 管道或指令:从管道或指令中获取输入字段的实际值,而不是修改后的值 - Angular Pipe or Directive: Get real value of Input field instead of modified value from pipe or directive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM