Angular JS Magazine

vineri, 19 septembrie 2014

Using the Number Filter

This tip shows you how to use the Number built-in Angular filter to format some number as:

- 3 decimals
- 0 decimals
- negative and 1 decimal

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="../angular/angular.min.js"></script>
    <link href="../bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../bootstrap/css/bootstrap-theme.css" rel="stylesheet" />
</head>
<body>
<div ng-app="" ng-init="atp=[
     { name: 'Nadal, Rafael (ESP)', rank: 1, guage: '1.43' },
     { name: 'Djokovic, Novak (SRB)', rank: 2, guage: '1' },
     { name: 'Federer, Roger (SUI)', rank: 3, guage: '1.233' },
     { name: 'Wawrinka, Stan (SUI)', rank: 4, guage: '1.1' },
     { name: 'Ferrer, David (ESP)', rank: 5, guage: '1.6' }]">

    <div id="atpPanel" class="panel">
        <h3 class="panel-header">ATP SINGLES RANKINGS</h3>
        <table class="table">
            <thead>
            <tr>
                <th>Name</th>
                <th>Rank</th>
                <th>Guage [number:3]</th>
                <th>Guage [number]</th>
                <th>Guage [number:1]</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="item in atp">
                <td>{{item.name}}</td>
                <td>{{item.rank}}</td>
                <td>{{item.guage | number:3}}</td>
                <td>{{item.guage | number}}</td>
                <td>{{-item.guage | number:1}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>


Niciun comentariu:

Trimiteți un comentariu