title: how to filter input value in AngularJS
body: <p>I'm trying to implement filtering on my input element.
  I want to make filtering for input with type="text"  field.
      For instance, if the model contain more than available characters than I want to change my input value.
  I've created <a href="https://jsfiddle.net/kiyanov/jvstfrso/10/" rel="nofollow">jsfiddle</a>
  I have directive that generate html template dynamically and it contains input field.</p>
  
  <pre><code>var app = angular.module('app', [])
  
  .controller('ctrlr', function($scope){
      $scope.myModel = "test";
      $scope.availableCharacters = 5;
      $scope.$watch('myModel', function(newValue, oldValue){
          if(!newValue){
              return;
          }
          if(newValue.length &gt; 5){
               $scope.cutString();       
           }
      });
      $scope.cutString = function(){
          var length = $scope.myModel.length;
          var string = $scope.myModel.slice(0, $scope.availableCharacters);
          var countStars = length - string.length;
          $scope.myModel = $scope.createStars(string, countStars);
      }
      $scope.createStars = function(string, countStars){
          for(var i = 1; i &lt;= countStars; i++){
                  string = string+'*';
              }
  
          return string;
      }
  })
  .directive('awesome' , function(){
      return {
          restrict:'E',
          template:'&lt;input type="text" ng-model="myModel" ng-value="myModel | filter:my" /&gt;'
      }
  })
  </code></pre>
  
  <p>Could it possibly to move my code into the filter function?  I have a lot of business logic and I don't want to keep my code in the controller, because it will be reusable directive.  </p>