AngularJS Tutorial - Filter input from value attribute








The following code shows how to filter input from value attribute.

Example


<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script type='text/javascript'>
function Ctrl($scope) {<!-- w  w  w  . j  a v  a2  s  . c o  m-->
  $scope.val = 1234.56789;
}
</script>
</head>
<body>
  <div ng-app="">
  <div ng-controller="Ctrl">

      WANTS:  {{val | number:2}} in "input" element<br>
    2 decimal in input:  <input  ng-model='val'> <br>
    2 decimal in input:  <input  type="number" step="0.01" ng-model='val'><br>
    2 decimal in input:  <input  ng-model='val' value="{{val |number:2}}"> <br>

  </div>
</div>
</body>
</html>

The code above is rendered as follows: