上代码:
<!DOCTYPEhtml> <htmlng-app="app"> <head> <Metacharset="UTF-8"> <title></title> <scriptsrc="lib/angular.js"></script> <script> varapp=angular.module('app',[]); app.controller('selectController',function($scope){ $scope.mycity='上海'; $scope.Cities=[{id:1,name:'北京',group:'中国'},{id:2,name:'上海',{id:3,name:'广州',group:'中国'}]; }); </script> </head> <body> <divng-controller="selectController">{{mycity}} <selectng-model="mycity"ng-options="v.nameasv.nameforvinCities"> </select> </div> </body> </html>
"v.name as v.name for v in Cities"这段代码最重要,
Cities是数据来源,
v是Cities中的子数据,
第二个v.name将会展示在option中,
第一个v.name将会把值和ng-model="mycity"进行同步。