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

Commit 301a737

Browse files
committed
fix($rootScope): Internal state consistency
During a recursive $apply, clear the state only if the state was set in that call.
1 parent 0400dc9 commit 301a737

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ng/rootScope.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1038,13 +1038,17 @@ function $RootScopeProvider() {
10381038
* @returns {*} The result of evaluating the expression.
10391039
*/
10401040
$apply: function(expr) {
1041+
var doCleanPhase = false;
10411042
try {
10421043
beginPhase('$apply');
1044+
doCleanPhase = true;
10431045
return this.$eval(expr);
10441046
} catch (e) {
10451047
$exceptionHandler(e);
10461048
} finally {
1047-
clearPhase();
1049+
if (doCleanPhase) {
1050+
clearPhase();
1051+
}
10481052
try {
10491053
$rootScope.$digest();
10501054
} catch (e) {

test/ng/rootScopeSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,19 @@ describe('Scope', function() {
15051505
}));
15061506

15071507

1508+
it('should not clear the state when calling $apply during an $apply', inject(
1509+
function($rootScope) {
1510+
$rootScope.$apply(function() {
1511+
expect(function() {
1512+
$rootScope.$apply();
1513+
}).toThrowMinErr('$rootScope', 'inprog', '$apply already in progress');
1514+
expect(function() {
1515+
$rootScope.$apply();
1516+
}).toThrowMinErr('$rootScope', 'inprog', '$apply already in progress');
1517+
});
1518+
}));
1519+
1520+
15081521
it('should throw an exception if $apply is called while flushing evalAsync queue', inject(
15091522
function($rootScope) {
15101523
expect(function() {

0 commit comments

Comments
 (0)