AngularJS提交模糊,模糊关键preSS [英] AngularJS submit on blur and blur on keypress
问题描述
我要当一个输入字段模糊一些数据提交给服务器。用户也应该能够通过pressing模糊输入字段中输入。
I want to submit some data to the server when a input field is blurred. The User should also be able to blur the input field by pressing enter.
不幸的是这将导致以下: $ rootScope:inprog:$正在进行中的错误已经适用
Unfortunately this results in the following: $rootScope:inprog: $apply already in progress error.
Plunkr - !在此先感谢
Plunkr - thanks in advance!
推荐答案
下面是发生了什么:
- 您$ P $ PSS输入
- NG-的keydown触发(消化开始)
- 您拨打
target.blur()
- NG-模糊触发器和尝试启动另一摘要周期
- 角抱怨
该模糊同步执行,并立即触发处理程序没有完成的第一个摘要。
The blur is executed synchronously and immediately triggers the handler without finishing the first digest.
在我看来,这是不是与你的code的一个问题,而是一个角度错误。我一直在试图想出一个更好的解决方案,但我只能找到:
In my opinion, this is not a problem with your code, but rather an Angular bug. I've been trying to think of a better solution, but I can only find:
app.controller('BlurCtrl', function($scope, $timeout) {
$scope.blurModel = "I'm the value"
$scope.blurOnEnter = function( $event ) {
if ( $event.keyCode != 13 )
return
// this will finish the current digest before triggering the blur
$timeout(function () { $event.target.blur() }, 0, false);
}
$scope.onBlur = function() {
$scope.result = this.blurModel
}
})
这篇关于AngularJS提交模糊,模糊关键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!