NG-模糊模型的更新值不缴费情况 [英] ng-blur the model's updated value is not avaiable in event
问题描述
我现在用的NG-模型选项,以prevent我的文字输入的模型被更新,直到焦点将丢失。这部分的所有作品。不过,我需要文本输入失去焦点和模型更新后处理该事件。在这种情况下,我需要进入新的模型的更新值,而不是旧的。
我试图用NG-blur事件,但是,我的处理程序里面的值是旧的价值,而不是进入新的价值。难道我做错了什么,或是否有更好的方式来获得对新犯的模型值的文本输入失去焦点后?
<输入类型=文本
NG-模式选项={updateOn:'模糊',反跳:0}
NG-模式=vm.myModel.amount
NG-模糊=vm.handleBlurEvent(vm.myModel.amount)/>
vm.handleBlurEvent =功能(项目)
{
//alert(item.amount); //古量 - 不进入新的金额
}
这是由previous响应返工 user1750537 一>,延至控制模糊模型更新,然后处理更改一次,无需反跳和模型价值将按照预期的变化逻辑之前设置。
<输入类型=文本
NG-模式选项={updateOn:'模糊'}
NG-模式=vm.myModel.amount
NG-变化=vm.handleChangeEvent(vm.myModel.amount)/>vm.handleChangeEvent =功能(项目)
{
警报(item.amount); //新节目新的金额:-)
}
I am using the ng-model-options to prevent my text input's model from being updated until the focus is lost. That part all works. However, I need to handle the event after the text input loses focus and the model is updated. In that event I need access to the NEW model's updated value, not the old one.
I am trying to use the ng-blur event, however, inside my handler the value is the old value, not the new value entered. Am I doing something wrong or is there a better way to get the newly committed model value after the text input loses focus?
<input type="text"
ng-model-options="{ updateOn: 'blur', debounce:0 }"
ng-model="vm.myModel.amount"
ng-blur="vm.handleBlurEvent(vm.myModel.amount)" />
vm.handleBlurEvent = function(item)
{
//alert(item.amount); //Old amount - not new amount entered
}
This is reworked from previous response by user1750537, delay the model update until control blur and then process the change once, no de-bounce required and the model value will be set before your change logic as expected.
<input type="text"
ng-model-options="{ updateOn: 'blur' }"
ng-model="vm.myModel.amount"
ng-change="vm.handleChangeEvent(vm.myModel.amount)" />
vm.handleChangeEvent = function(item)
{
alert(item.amount); //new shows the NEW amount :-)
}
这篇关于NG-模糊模型的更新值不缴费情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!