angularjs select

Posted 争取过得好一点

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

  

以上是关于angularjs select的主要内容,如果未能解决你的问题,请参考以下文章

从 AngularJS url 中删除片段标识符(# 符号)

初入AngularJS基础门

AngularJs - SELECT 中的 ng-model

<select> 上的 AngularJS 验证,带有提示选项

AngularJS ——ngResourceRESTful APIs 使用

浅谈AngularJS中的$parse和$eval