每个按键上的Angular 2更改事件 [英] Angular 2 change event on every keypress

查看:35
本文介绍了每个按键上的Angular 2更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在输入的焦点已更改后才调用change事件.如何使事件在每次按键上触发?

The change event is only called after the focus of the input has changed. How can I make it so that the event fires on every keypress?

<input type="text" [(ngModel)]="mymodel" (change)="valuechange($event)" />
{{mymodel}}

第二个绑定在每次按键时都会改变.

The second binding changes on every keypress btw.

推荐答案

我只是使用了事件输入,它的工作情况如下:

I just used the event input and it worked fine as follows:

.html文件中的

<input type="text" class="form-control" (input)="onSearchChange($event.target.value)">

.ts文件中的

onSearchChange(searchValue: string): void {  
  console.log(searchValue);
}

这篇关于每个按键上的Angular 2更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆