angularjs select

<html>
<head>
	<meta charset="utf-8">
	<title>select 測試頁面</title>
	<script src="angular1.5.8.min.js"></script>
</head>
<body ng-app="app">
<div ng-controller="getnames">
	<p>with ng-option,這種方式能夠取到一個對象</p>
		<select ng-model="selectedPeople" ng-options="people.name for people in peoples"></select>
	    your choice is :{{selectedPeople.name}}

	<!-------------------------------------------------------------------------------------------->    
	<p>without ng-option,這種方式只能取到一個字符串</p>
		<select ng-model="selectedName">
			<option  ng-repeat="people in peoples" value="{{people.age}}">{{people.name}}</option>
		</select>
	    your choice is :{{selectedName}}
</div>
</body>
<script type="text/javascript">
	var app =angular.module("app",[]);
	app.controller("getnames",function($scope){
		$scope.peoples=[{name:"quannan",age:"100"},{name:"shenzhen",age:"1200"},{name:"shnaghai",age:"1003"}];
		//$scope.names=["quannan","shenzhen","shanghai"];
	});
</script>
</html>
相關文章
相關標籤/搜索