我需要以同样的方式对用户触摸表单控件之一的事件做出反应.这个类 似乎定义了 valueChanges Observable 并且 touched 属性被定义为一个布尔值.有没有办法对控制触摸"事件做出反应? 解决方案 ng2 没有提供直接的方式来对触摸事件做出反应.它使用 (input) 事件来触发 valueChanges 事件和 (blur) 事件来设置 touched/untouched 属性AbstractControl.因此,您需要在模板中手动订阅所需事件并在您的组件类中处理它.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.This class seem to define the valueChanges Observable and the touched property is defined as a boolean.Is there a way to to react to the "control touched" event? 解决方案 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 上观察触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 06:33
查看更多