如何在Angular 2 NgForm上观察触摸事件? [英] How to observe touched event on Angular 2 NgForm?

查看:62
本文介绍了如何在Angular 2 NgForm上观察触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以对NgFormvalueChanges可观察属性订阅回调,以便对表单控件的值的变化做出反应.

It is possible to subscribe a callback to an NgForm's valueChanges observable property in order to react to changes in the values of the controls of the form.

我需要以相同的方式对用户触摸表单控件之一的事件做出反应.

I need, in the same fashion, to react to the event of the user touching one of the form controls.

此类似乎定义了valueChanges Observable,而touched属性定义为布尔值.

This class seem to define the valueChanges Observable and the touched property is defined as a boolean.

是否可以对触摸控件"事件做出反应?

推荐答案

ng2没有提供直接的方式对触摸事件做出反应.它使用( input )事件触发 valueChanges 事件和( blur )事件来设置 touched/untouched 属性 AbstractControl . 因此,您需要在模板中手动订阅所需的事件,并在组件类中对其进行处理.

There is not direct way provided by ng2 to react on touched event. It uses (input) event to fire the valueChanges event and (blur) event to set touched/untouched property of AbstractControl. So you need to manually subscribe on desired event in the template and handle it in your component class.

这篇关于如何在Angular 2 NgForm上观察触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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