AngularJS应用程序失败,Inprog范围正在进行中

时间:2015-07-31 22:52:15

标签: angularjs

现在已经对此错误进行了数小时的故障排除。困难的部分是我甚至没有使用$ 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)

当它使用触发器点击代码调用该函数时会发生这种情况。这是一个指令。这是一个片段

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

1 个答案:

答案 0 :(得分:1)

向您的指令注入$ timeout,然后使用它

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

Angular将在触发点击之前等待您的DOM被检查。

PS:angular为您提供了获取错误信息的链接。您发布了该链接,但尚未阅读该链接。