title: Why is ngModel.$setViewValue(...) not working from
body: <p>I'm writing an directive which needs an isolated scope, but I want to bind it to the parent scope via <a href="http://docs.angularjs.org/api/ng.directive%3angModel.NgModelController">ngModel</a>.</p>
  
  <p>Here the problem is that the parent's scope value is not getting changed.</p>
  
  <p>Markup</p>
  
  <pre><code>&lt;form name="myForm" ng-app="customControl"&gt;
      &lt;div ng-init="form.userContent"&gt;&lt;/div&gt;
      &lt;div contenteditable name="myWidget" ng-model="form.userContent" required&gt;Change me!&lt;/div&gt;
      &lt;span ng-show="myForm.myWidget.$error.required"&gt;Required!&lt;/span&gt;
      &lt;hr /&gt;
      &lt;textarea ng-model="form.userContent"&gt;&lt;/textarea&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>angular.module('customControl', []).directive('contenteditable', function() {
      return {
          restrict : 'A', // only activate on element attribute
          require : '?ngModel', // get a hold of NgModelController
          scope: {},
          link : function(scope, element, attrs, ngModel) {
              if (!ngModel)
                  return; // do nothing if no ng-model
  
              // Specify how UI should be updated
              ngModel.$render = function() {
                  element.html(ngModel.$viewValue || '');
              };
  
              // Listen for change events to enable binding
              element.bind('blur keyup change', function() {
                          scope.$apply(read);
                      });
              read(); // initialize
  
              // Write data to the model
              function read() {
                  ngModel.$setViewValue(element.html());
              }
          }
      };
  });
  </code></pre>
  
  <p>Demo: <a href="http://jsfiddle.net/arunpjohny/Hwv7E/4/">Fiddle</a>.</p>
  
  <p>This works fine if I don't use a isolated scope for the directive</p>
  
  <p>Demo: <a href="http://jsfiddle.net/arunpjohny/Hwv7E/3/">Fiddle</a>.</p>