title: AngularJS - Is it possible to change the value of ngModel attribute on directive in link or compile?
body: <p>I am trying to create a directive that will add an ngModel attribute to a tag based on the attribute value.  For example:</p>
  
  <pre><code>angular.module('myModule').
    directive('myDirective', function() {
      return {
        link: function(scope, elem, attrs) {
          var modelName = 'myPrefix.' + attrs.name;
          attrs.$set('ngModel', modelName);
        }
      };
    });
  </code></pre>
  
  <p>So that this html:</p>
  
  <pre><code>&lt;input name="foo" my-directive&gt;&lt;/input&gt;
  </code></pre>
  
  <p>is compiled into</p>
  
  <pre><code>&lt;input name="foo" ng-model="myPrefix.foo" my-directive&gt;&lt;/input&gt;
  </code></pre>
  
  <p>It takes the name of the input, attaches a prefix, and sets the ngModel attribute to that value.</p>
  
  <p>When I try to do this in the link function, it seems like the <code>input</code> isn't being registered with the formController, so that <code>form.foo</code> returns undefined.</p>
  
  <p>Is it possible to accomplish what I'm trying to do?</p>
  
  <p>EDIT:</p>
  
  <p>It seems like the <code>ngModel</code> attribute is being set on the HTML, but it is not being registered with the form, or the ngModelController is not being instantiated.  If I look at the value of <code>ngModel</code> in the scope, it does not change when I modify the input.</p>