首页 > 代码库 > angular中的ng-options 用法

angular中的ng-options 用法

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="http://www.mamicode.com/js/angular-1.3.0.js" ></script>
</head>
<body>
<div ng-app="hd" ng-controller=‘ctrl‘>
<select ng-options=" v.value as v.name for v in data" ng-model="city">
<option value=http://www.mamicode.com/‘‘>请选择
</select>
{{city}}
</div>
<script>
var m = angular.module(‘hd‘,[]);
m.controller(‘ctrl‘,[‘$scope‘,function($scope){
$scope.city=‘qing hua‘; //默认选中
$scope.data=http://www.mamicode.com/[{name:‘北大‘,value:‘bei da‘},{name:‘清华‘,value:‘qing hua‘},{name:‘南开‘,value:‘nankai‘}];
}]);
</script>
</body>
</html>

angular中的ng-options 用法