ng-options將數據對象作爲數據源

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title></title>

<link rel="stylesheet" href="">

</head>

<body>

<div ng-app="myApp" ng-controller="myCtrl">

<select ng-model="selectedSite" ng-options="x for (x,y) in sites"></select>

<h1>你選擇的是: `selectedSite`</h1>

</div>

</body>

<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>

<script>

var app = angular.module("myApp",[]);

app.controller("myCtrl",function($scope){

$scope.sites = {

site01 : "Google",

    site02 : "Runoob",

    site03 : "Taobao"

    };

});

</script>

</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章