title: What is $$phase in AngularJS?
body: <p>I found this code snippet which is part of a angular directive someone wrote for bootstrap modal.</p>
  
  <pre><code>//Update the visible value when the dialog is closed                                                                                                                                                                                                            
                  //through UI actions (Ok, cancel, etc.)                                                                                                                                                                                                                         
                  element.bind("hide.bs.modal", function () {                                                                                                                                                                                                                     
                      scope.modalVisible = false;                                                                                                                                                                                                                                 
                      if (!scope.$$phase &amp;&amp; !scope.$root.$$phase)                                                                                                                                                                                                                 
                          scope.$apply();                                                                                                                                                                                                                                         
                  });  
  </code></pre>
  
  <p>I understood that this part is for the latter half of two way binding we bind to hide.bs.modal event and update modal when UI changes.</p>
  
  <p>I just wanted to know why is the person checking $$phase for scope and rootScope before calling apply ?</p>
  
  <p>Can't we straightaway call apply ?</p>
  
  <p>What is $$phase here?</p>
  
  <p>I tried searching a lot, couldn't find any good explanation. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>I found where I saw the example:</strong>
  <a href="https://stackoverflow.com/questions/19644405/simple-angular-directive-for-bootstrap-modal">Simple Angular Directive for Bootstrap Modal</a></p>