Angular.js – using the number filter with fraction

A simple Angular.js example of using the number filter with fraction.
<!DOCTYPE html>
<html ng-app="testApp">
<head>

    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen Angular.js example"/>

    <title>Tizen Angular.js example</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>

    <script src="js/jquery-2.1.4.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/angular.min.js"></script>
    <script>

        var app = angular.module('testApp', []);

            app.controller('AppController', function($scope) {

                $scope.people= [{name:'Bananas', kg: 20},
                                {name:'Oranges', kg: 15.3453453453},
                                {name:'Citrons', kg: 32.100000000000000021},
                                {name:'Apples', kg: 9.445}];

            });

    </script>
</head>

<body>
<div ng-controller="AppController">
  <p>Warehouse listing</p>

      <ul>
        <li ng-repeat="x in people">
          {{ x.name + ', ' + (x.kg | number: 3 ) + ' kg' }}
        </li>
      </ul>

</div>
</body>

</html>

Responses

0 Replies