title: Why can't I use Angular an angular directive's $set function to set ngPattern, ngMinlength and ngMaxlength?
body: <p>This is going to sound weird, but, even if it is bad practice or something, how would I get this:</p>
  <h1>html:</h1>
  <pre><code>&lt;div ng-controller='CtrlCtrl as ctrlr'&gt;  
    &lt;input account /&gt;
    &lt;button ng-disabled='ctrlr.isValid()'&gt;Click&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  <p>to look like this:</p>
  <h1>goal:</h1>
  <pre><code>&lt;div ng-controller='CtrlCtrl as ctrl'&gt;  
   &lt;input type='text' name='derp_herp' ng-model='ctrlr.goal'
     ng-maxlength='10' ng-minlength='3' ng-required='true'
     ng-pattern='/^\d+$/' ng-focus='ctrlr.action()' ng-blur='ctrlr.validate()'
     ng-change='ctrlr.checkValid()'
   /&gt;
  &lt;/div&gt;
  </code></pre>
  <h1>WITHOUT doing this:</h1>
  <pre><code>app.directive('accounts', [function() {
    return {
      restrict: 'A',
      scope: {},
      transclude: true,
      templateUrl: 'inpt.html', // &lt;==== no.
      // template: 'the contents of inpt.html' &lt;==== no.
      link: function(scope, elem, attrs, model) {
  
         //this is where things vary.
  
      }
    }
  </code></pre>
  <p>.<br />
  .<br />
  .</p>
  <h1>A few things I've tried- <a href="http://embed.plnkr.co/Mc63qu" rel="nofollow noreferrer">(plunkr)</a></h1>
  <h3>assume this part is constant:</h3>
  <pre><code>function action(a, b, c){ alert(a); alert(b); alert(c); }
  
  app.directive('accounts', ['$compile', function($compile) {
    return {
      require: 'ngModel',
      restrict: 'A',
      scope: {},
      transclude: true,
      link: function(scope, elem, attrs, model) {
  
         //this is where things vary.
  
      }
    }
  }]);
  </code></pre>
  <p>.<br />
  .<br />
  .</p>
  <h3>Every iteration of the following (commenting stuff out, etc):</h3>
  <pre><code> var a, b, c;
    attrs.ngPattern      = /^\d+$/;
    attrs.ngMinlength    = '3';
    attrs.ngMaxlength    = '10';
  
    attrs.ngChange = function(){
    a=  Object.keys(model);
    b=  Object.keys(elem);
    c=  Object.keys(attrs);
      action(a, b, c );
    }
  
    $compile(attrs);
    $compile(elem)      
    $compile(scope)
  </code></pre>
  <h1>and:</h1>
  <pre><code>   var a, b, c;
        if(model.$invalid){
          elem.addClass('test');
        }
        
        attrs.$set('ngMinlength', '3')
        attrs.$set('ngMaxlength', '3')
        attrs.$set('ngPattern', /^\d+$/);
        $attrs.$set('ngChange','action()');
        
  
        $compile(attrs);
        $compile(elem)      
        $compile(scope)
        
  </code></pre>
  <h1>and tried with a controller</h1>
  <pre><code>app.controller(&quot;CtrlCtrl&quot;, ['$scope', '$element','$attrs', '$compile',
  function ($scope, $elem, $attrs, $compile) {
    var meta = this, a, b,c;
    this.meta = meta;
    this.ctrlr = meta || {}
    this.ctrlr.modl = &quot;abc&quot;;
    $attrs.$set('ngMinlength', '3')
    $attrs.$set('ngMaxlength', '10')
    $attrs.$set('ngPattern', /^\d+$/);
    
    a=  Object.keys($scope);
    b=  Object.keys($elem);
    c=  Object.keys($attrs);
    
    $attrs.$set.ngChange = function(){
      action(a, b, c );
    }
  
    $compile($scope);
    $compile($attrs);
    $compile($elem)      
    $compile($scope)  
    // console.log(a);
    // console.log(b);
    // console.log(c);
  
    }
  ]);
  </code></pre>
  <p>I have no idea why this is difficult. The documentation seems detailed enough at first, but good lord is it not enough once you get in the trenches. I've watched every egghead.io video, read so many things... seriously. If this were another language, I'd be teaching it by now.</p>