From 4e15c4fb47e93c1f6619a09125bc9a350e39b113 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Tue, 13 Aug 2013 20:51:03 -0400 Subject: chore($rootScope): provide support to execute a function after the digest cycle is complete --- src/ng/rootScope.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/ng/rootScope.js') diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 18c54434..d3b2762d 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -119,6 +119,7 @@ function $RootScopeProvider(){ this['this'] = this.$root = this; this.$$destroyed = false; this.$$asyncQueue = []; + this.$$postDigestQueue = []; this.$$listeners = {}; this.$$isolateBindings = {}; } @@ -133,6 +134,7 @@ function $RootScopeProvider(){ Scope.prototype = { + constructor: Scope, /** * @ngdoc function * @name ng.$rootScope.Scope#$new @@ -167,6 +169,7 @@ function $RootScopeProvider(){ child.$root = this.$root; // ensure that there is just one async queue per $rootScope and it's children child.$$asyncQueue = this.$$asyncQueue; + child.$$postDigestQueue = this.$$postDigestQueue; } else { Child = function() {}; // should be anonymous; This is so that when the minifier munges // the name it does not become random set of chars. These will then show up as class @@ -494,6 +497,7 @@ function $RootScopeProvider(){ var watch, value, last, watchers, asyncQueue = this.$$asyncQueue, + postDigestQueue = this.$$postDigestQueue, length, dirty, ttl = TTL, next, current, target = this, @@ -566,6 +570,14 @@ function $RootScopeProvider(){ } while (dirty || asyncQueue.length); clearPhase(); + + while(postDigestQueue.length) { + try { + postDigestQueue.shift()(); + } catch (e) { + $exceptionHandler(e); + } + } }, @@ -696,6 +708,10 @@ function $RootScopeProvider(){ this.$$asyncQueue.push(expr); }, + $$postDigest : function(expr) { + this.$$postDigestQueue.push(expr); + }, + /** * @ngdoc function * @name ng.$rootScope.Scope#$apply -- cgit v1.2.3