title: Update model from directive from $apply or $digest cycle in AngularJS
body: <p>I try update model from directive and have some trouble when $apply or $digest already in progress. And I have some questions:</p>
  
  <ol>
  <li>Why <code>scope[attrs.ngModel]</code> is exist, but <code>ngModel.$modelValue</code> isn't
  exist in $apply phase?</li>
  <li>Why view can be not always updated in $digest phase (especially in difficult situations)?</li>
  <li>Is $digest phase local $digest() or $root.$digest() (from $apply()) in my example?</li>
  </ol>
  
  <pre class="lang-js prettyprint-override"><code>require: '?ngModel',
  link: function(scope, element, attrs, ngModel) {
  
    element.bind('myEvent', function(e) {        
      //Update model from directive in phase:               $apply  |  $digest
  
      scope[attrs.ngModel].value = scope.$$phase; //Model: '$apply' | '$digest'
      //or
      ngModel.$modelValue.value  = scope.$$phase; //Model: 'none'   | '$digest'
      //or
      ngModel.$modelValue.value  = scope.$$phase; //Model: ''       | '$digest'
      ngModel.$setViewValue(ngModel.$modelValue);
    });
  }
  </code></pre>
  
  <p>Live demo: <a href="http://plnkr.co/edit/gVY6GJejEKCLdTIXNAzK?p=preview" rel="nofollow">http://plnkr.co/edit/gVY6GJejEKCLdTIXNAzK?p=preview</a></p>