Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Error: "$digest already in progress", when using autofocus and ng-focus #6364

Closed
RichardH9L opened this issue Feb 20, 2014 · 3 comments
Closed

Comments

@RichardH9L
Copy link

When autofocus is used on a input field which also has ng-focus and using ng-include on the page, angularjs throws: $digest already in progress

Code to reproduce

<!DOCTYPE html>
<html lang="en" ng-app>
  <head>
    <script src="http://code.angularjs.org/1.2.13/angular.js"></script>
  </head>

  <body>
    <header ng-include="'header.html'"></header>
    <input name="test" type="text" ng-focus="x = true" autofocus>
  </body>

</html>

Plunkr: http://plnkr.co/edit/diGeK3lylou3ziNpEwgj

Stacktrace:

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.2.13/$rootScope/inprog?p0=%24digest
    at http://code.angularjs.org/1.2.13/angular.js:78:12
    at beginPhase (http://code.angularjs.org/1.2.13/angular.js:12358:15)
    at Scope.$apply (http://code.angularjs.org/1.2.13/angular.js:12144:11)
    at HTMLInputElement.<anonymous> (http://code.angularjs.org/1.2.13/angular.js:18085:21)
    at http://code.angularjs.org/1.2.13/angular.js:2626:10
    at forEach (http://code.angularjs.org/1.2.13/angular.js:311:20)
    at HTMLInputElement.eventHandler (http://code.angularjs.org/1.2.13/angular.js:2625:5)
    at scroll (http://code.angularjs.org/1.2.13/angular.js:3823:26)
    at Scope.$eval (http://code.angularjs.org/1.2.13/angular.js:12045:28)
    at Scope.$digest (http://code.angularjs.org/1.2.13/angular.js:11871:31) angular.js:9503
(anonymous function) angular.js:9503
(anonymous function) angular.js:6914
Scope.$apply angular.js:12147
(anonymous function) angular.js:18085
(anonymous function) angular.js:2626
forEach angular.js:311
eventHandler angular.js:2625
scroll angular.js:3823
Scope.$eval angular.js:12045
Scope.$digest angular.js:11871
Scope.$apply angular.js:12151
(anonymous function) angular.js:1304
invoke angular.js:3720
doBootstrap angular.js:1302
bootstrap angular.js:1316
angularInit angular.js:1265
(anonymous function) angular.js:20869
trigger angular.js:2355
(anonymous function) angular.js:2626
forEach angular.js:311
eventHandler

This might be related, but I'm not sure: #4979

@caitp
Copy link
Contributor

caitp commented Feb 20, 2014

The fix for #4979 (if it also async applies on focus) would fix this, yes. In Angular 2.0, we shouldn't have this problem at all, hopefully heres hoping. I'm going to mark this as a duplicate and make a note that focus also can suffer from this problem under some circumstances.

@Narretz
Copy link
Contributor

Narretz commented Feb 20, 2014

How is Angular 2 going to handle this?

@caitp
Copy link
Contributor

caitp commented Feb 20, 2014

@Narretz hopefully we can get rid of dirty-checking entirely (and therefore get rid of the digest cycle), but that may not be feasible for everything, it depends on how things progress I suppose.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants