Alan2
Alan2

Reputation: 24572

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.

Upvotes: 0

Views: 36

Answers (1)

Vinay K
Vinay K

Reputation: 5572

Try $timeout

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

Upvotes: 1

Related Questions