title: Angular limit input[number] length
body: <p>Using the directive in <a href="https://stackoverflow.com/questions/24701205/how-can-you-limit-the-value-from-input-using-angularjs">How to limit input[number]</a> cause a issue.</p>
  
  <p>When in input reached max I want to mark the input(double right click on the input) and then pressing a digit to make it change the entire input don't change it, due to the directive <code>e.preventDefault();</code>
  The selection event can be view in:</p>
  
  <pre><code>angular.element(elem).on("select", function(e) {
                  console.log(e);
  
              });
  </code></pre>
  
  <p>What is the best way to fix it?
  The directive:</p>
  
  <pre><code>angular.module('myApp')
    .directive('limitTo', limitTo);
  
  function limitTo() {    
      return {
          restrict: "A",
          link: function(scope, elem, attrs) {
              var limit = parseInt(attrs.limitTo);
              angular.element(elem).on("keypress", function(e) {
                  if (this.value.length == limit){
                      e.preventDefault();
                  } 
              });
          }
      }
  };
  </code></pre>
  
  <p>And use:</p>
  
  <pre><code>    &lt;input type="number" class="form-control form-control-lg"  limit-to="6" 
      ng-model="vm.details.m_inputSMS" placeholder = {{vm.configProprs.kodPlaceHolder}} name ="m_inputSMS" id="m_inputSMS"
      ng-model-options="{ updateOn: 'blur' }"required/&gt;
  </code></pre>