简体   繁体   English

如何延迟操作,直到$ apply完成?

[英]How can I delay an action until after the $apply is finished?

Given this code: 给出以下代码:

   <body ng-keydown="key($event);">

   $scope.key = function ($event) {
       if (key == 13) {
           document.getElementById("aButton").click();
       }
   }

When I run the code I am getting a message saying there is: 运行代码时,我收到一条消息,提示:

   $apply already in progress

Can someone give me some advice on how I can fix my problem. 有人可以给我一些有关如何解决问题的建议。

Try $timeout 尝试$timeout

$scope.key = function ($event) {
       if ($event.which == 13) {
           $timeout(function(){
              document.getElementById("aButton").click();
           })
       }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将功能延迟到加载动态页面的功能完成之后? - How can I delay a function until after a function which loads a dynamic page is finished? 如何在Geocoder完成之前延迟submit()事件? - How to delay submit() event until after Geocoder is finished? 如何延迟ng-init方法,直到我的作用域变量完成加载? - How can I delay the ng-init method until my scope Variable finished loading? 如何延迟传递道具直到 setState() 完成? - How do I delay passing props until setState() is finished? 我怎样才能延迟动作,机器人会忽略第二个命令,直到我执行第一个命令? - How i can delay the action, to bot will ignore second command until i do first command? 如何延迟计数器直到动画结束 - How to delay a counter until animation is finished 在异步循环完成之后,如何等待发送明确的响应? - How can I wait to send an express response until after async loop is finished? 延迟jQuery UI对话框关闭,直到回调完成后 - Delay jquery ui dialog close until after callback is finished 如何延迟来自用户表单的 POST 请求,直到收到来自 Stripe 的 webhook POST 之后? - How can I delay a POST request from a user form until AFTER a webhook POST from Stripe is received? 如何在前一个函数完成之前进行语句? - How can I make a statement wait until a previous function is finished?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM