This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathselect.html
78 lines (68 loc) · 2.57 KB
/
select.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>Select - AngularJS Test</title>
<style type="text/css">
.test-div {margin:15px;padding:15px;border:1px solid #ccc;}
</style>
</head>
<body>
<div class="test-div" ng-controller="myCtrl1">
<select ng-model="selectedCar">
<option ng-repeat="car in cars" value="{{car.brand}}">{{car.name}}</option>
</select>
<p>Selected Car: {{selectedCar}}</p>
</div>
<div class="test-div" ng-controller="myCtrl2">
<select ng-model="selectedColor" ng-options="color for color in colors"></select>
<p>Selected Color: {{selectedColor}}</p>
</div>
<div class="test-div" ng-controller="myCtrl3">
<select ng-model="selectedCar" ng-options="car.brand for car in cars"></select>
<p>Selected: {{selectedCar.color}} {{selectedCar.name}}</p>
</div>
<div class="test-div" ng-controller="myCtrl4">
<select ng-model="selectedCar" ng-options="x for (x, y) in cars"></select>
<p>Selected: {{selectedCar.color}} {{selectedCar.name}}</p>
</div>
<script type="text/javascript" src="static/js/angular-1.5.8.js"></script>
<script type="text/javascript">
/**
* Dropdowns made with ng-options allows the selected value to be an object,
* while dropdowns made from ng-repeat has to be a string.
* When the selected value can be an object, it can hold more information, and your application can be more flexible.
*
* Using an object as the data source, x represents the key, and y represents the value: x for (x, y) in
* The selected value will always be the value in a key-value pair.
* The value in a key-value pair can also be an object.
*/
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl1", function($scope) {
$scope.cars = [
{brand:"BMW",name:"宝马"},
{brand:"Benz",name:"奔驰"},
{brand:"Audi",name:"奥迪"}
];
});
myApp.controller("myCtrl2", function($scope) {
$scope.colors = ["Red", "Green", "Blue"];
});
myApp.controller("myCtrl3", function($scope) {
$scope.cars = [
{brand:"BMW",name:"宝马",color:"Red"},
{brand:"Benz",name:"奔驰",color:"Green"},
{brand:"Audi",name:"奥迪",color:"Blue"}
];
});
myApp.controller("myCtrl4", function($scope) {
$scope.cars = {
BMW: {name:"宝马",color:"红色"},
Benz: {name:"奔驰",color:"蓝色"},
Audi: {name:"奥迪",color:"绿色"}
};
});
</script>
</body>
</html>