title: When does the digest get triggered in AngularJS
body: <p>All:</p>
  
  <p>I got a question about how angularjs data digest monitor the changing of scope data, for example:</p>
  
  <pre><code> &lt;button ng-click="changename()"&gt;{{name}}&lt;/button&gt;
  </code></pre>
  
  <p>And the data change function is like:</p>
  
  <pre><code>            $scope.name = "Change Name";
              $scope.changename = function(){
                  $scope.name = "name1";
                  $scope.name = "name2";
              }
  
              $scope.$watch("name", function(newname, oldname){
                  if(newname!=oldname){
                      console.log("new: "+newname, "old: "+oldname);
                  }
              });
  </code></pre>
  
  <p>This changename function change scope.name twice in a row, but the watcher can <strong>only catch the change from "Change Name" to "name2"</strong> ( the console only print "new: name2 old: Change Name")</p>
  
  <p>Could anyone <strong>confirm my guess</strong> that the digest cycle only start after a function block finish executing?</p>
  
  <p>Thanks</p>