Angular JS Magazine

luni, 8 septembrie 2014

Creating optgroup Elements

You can easily create optgroup elements by using Angular like below:

<!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, 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)' },
     { name: 'Tsonga, Jo-Wilfried (FRA)', rank: 11, age: '29 (17.04.1985)', birthplace: 'Le Mans, France', height: '188 cm', weight: '200 lbs (91 kg)' },
     { name: 'Simon, Gilles (FRA)', rank: 26, age: '29 (27.12.1984)', birthplace: 'Nice, France', height: '183 cm', weight: '154 lbs (70 kg)' },
     { name: 'Mayer, Leonardo (ARG)', rank: 25, age: '27 (15.05.1987)', birthplace: 'Corrientes, Argentina', height: '188 cm', weight: '183 lbs (83 kg)' }]">

    <div id="atpPanel" class="panel">
        <div class="well">
            <div class="form-group">
                <label>Select an Player:</label>
                <select ng-model="selectedPlayer"
                            ng-options="item.name group by item.height for item in atp">
                    <option value="">(Pick One Player)</option>
                </select>
                <div class="well">
                    <p>Selected: {{selectedPlayer || 'None'}}</p>
                </div>
            </div>
        </div>
    </div>
</body>
</html>