0

Been troubleshooting this error for many hours now. The hard part is that I am not even using $apply

Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.3.16/$rootScope/inprog?p0=%24apply
  at angular.js:63
  at beginPhase (angular.js:14901)
  at Scope.$digest (angular.js:14343)
  at HTMLDocument.dismissClickHandler (mm-foundation-tpls.js:3282)
  at HTMLDocument.jQuery.event.dispatch (jquery.js:4435)
  at HTMLDocument.elemData.handle (jquery.js:4121)
  at Object.jQuery.event.trigger (jquery.js:4350)
  at HTMLInputElement.<anonymous> (jquery.js:4901)
  at Function.jQuery.extend.each (jquery.js:374)
  at jQuery.fn.jQuery.each (jquery.js:139)

it happens when it calls the function with the trigger click code. It's in a directive. Here is a snippet

  link: function ($scope, el) {
    $scope.openBrowse = function () {
      el.find('#container').trigger('click');
    };
  }
1
  • Could you show the whole directive and the template please. Looks like you have some conflicting event situation where your click event is being called twice in way Anuglar doesn't like. Do you have an ng-click directive or something on #container? Commented Jul 31, 2015 at 23:20

1 Answer 1

1

Inject $timeout to your directive and then use it

link: function ($scope, el) {
  $scope.openBrowse = function () {
    $timeout(function(){
      el.find('#container').trigger('click');
    });
  };
}

Angular will then wait for your DOM to be checked before triggering the click.

PS : angular gives you a link to get information about your error. You posted the link, but haven't read at all about the link.

Sign up to request clarification or add additional context in comments.

2 Comments

WOOOHOO! :) Thanks a lot! So the problem then was that it was triggering and container id wasn't rendered yet. Thank you so much!
The digest or apply cycle in angular is an internal process. In your case, your trigger was made in a apply and was triggering a kind of infinite loop of apply

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.