Quessions about $$phase in Scope object

54 views
Skip to first unread message

Zizon Qiu

unread,
Mar 16, 2014, 9:35:27 AM3/16/14
to ang...@googlegroups.com
hi,
 Recently,I come across the well known error:

Error: [$rootScope:inprog] $digest already in progress' 
 
 With some source reading,It seems that,$rootScope.$$phase is the direct cause.

 $$phase can be found at every Scope object,but only referenced/accessed by $rootScope.

 So,I wonder why this singular property be presented in every Scope object but not private to $rootScope?
 
 If $$phase is set in per-scope way,not stick to $rootScope,in my case the error mentioned above can be avoid.
 although,it do can be `avoid` in some other way.

 but,what I asking,is not how to avoid it,but why $$phase designed this way(not private to $rootScope)?

Ivan S

unread,
Mar 17, 2014, 4:02:54 AM3/17/14
to ang...@googlegroups.com
In fact, $$phase IS a property of the $rootScope object.

You can access it in child scopes since they prototypically inherit from the rootScope.

If you try to access it on isolated scope (like a directive with scope: {}), you will get "undefined".

Zizon Qiu

unread,
Mar 17, 2014, 4:45:32 AM3/17/14
to ang...@googlegroups.com
Isolate scopes DO have a $$phase as property while not-isolate scope don`t.
see https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js line:178 and line:125(Scope defination).

$rootScope is initialized in line 1037 with no other post-process, if I not missing something.



--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/pN-a3pR8UAc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Ivan Skryabin

unread,
Mar 17, 2014, 4:56:05 AM3/17/14
to ang...@googlegroups.com
You are right, isolated scopes have a $$phase property, but this
property is never used anyway.

If you look at $apply(), beginPhase() and clearPhase() you will see that
$rootScope.$$phase is always used for a digest cycle.

This makes sense because in every digest cycle you have to check ALL
properties for possible modifications : even isolated scopes can have
properties that are bound to parent properties via '=prop'.
Reply all
Reply to author
Forward
0 new messages