Angular JS Magazine

joi, 4 septembrie 2014

Example of Using ng-true-value and ng-false-value

The below tip shows you how to hide half of a list using a simple checkbox and the ng-true-value/ng-false-value attributes:

<!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="allOrHalf=1; atp=[
     { name: 'Nadal, Rafael (ESP)', rank: 1, age: '28 (03.06.1986)', birthplace: 'Manacor, Mallorca, Spain', height: '185 cm', weight: '188 lbs (85 kg)' },
     { name: 'Djokovic, Novak (SRB)', rank: 2, age: '27 (22.05.1987)', birthplace: 'Belgrade, Serbia', height: '188 cm', weight: '176 lbs (80 kg)' },
     { name: 'Federer, Roger (SUI)', rank: 3, age: '33 (08.08.1981)', birthplace: 'Basel, Switzerland', height: '185 cm', weight: '187 lbs (85 kg)' },
     { name: 'Wawrinka, Stan (SUI)', rank: 4, age: '29 (28.03.1985)', birthplace: 'Lausanne, Switzerland', height: '183 cm', weight: '179 lbs (81 kg)' },
     { name: 'Ferrer, David (ESP)', rank: 5, age: '32 (02.04.1982)', birthplace: 'Javea, Spain', height: '175 cm', weight: '160 lbs (73 kg)' }]">

    <div id="atpPanel" class="panel">
        <div class="well">
            <div class="checkbox">
                <label>
                    <input type="checkbox" ng-model="allOrHalf"
                           ng-true-value="2" ng-false-value="1">
                    Display all/half of records
                </label>
            </div>
        </div>
        <h3 class="panel-header">ATP SINGLES RANKINGS</h3>
                <table class="table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Rank</th>
                        <th>Age</th>
                        <th>Birthplace</th>
                        <th>Height</th>
                        <th>Weight</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="item in atp" ng-show="item.rank <= atp.length/allOrHalf">
                        <td>{{item.name}}</td>
                        <td>{{item.rank}}</td>
                        <td>{{item.age}}</td>
                        <td>{{item.birthplace}}</td>
                        <td>{{item.height}}</td>
                        <td>{{item.weight}}</td>
                    </tr>
                    </tbody>
                </table>

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



Niciun comentariu:

Trimiteți un comentariu