`
yianpuodiaotu
  • 浏览: 237842 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

angularjs select

    博客分类:
  • h5
阅读更多
1. 第一种方法
$scope.colors = [
  {name:'black', shade:'dark'},
  {name:'white', shade:'light'},
  {name:'red', shade:'dark'},
  {name:'blue', shade:'dark'},
  {name:'yellow', shade:'light'}
];
$scope.myColor =  $scope.colors[1]; // cannot be {name:'white', shade:'light'}


<select ng-model="myColor" ng-options="color.name for color in colors">
  <option value="">-- choose color --</option>
</select>

2. 第二种方法
$scope.colors = [
  {name:'black', shade:'dark'},
  {name:'white', shade:'light'},
  {name:'red', shade:'dark'},
  {name:'blue', shade:'dark'},
  {name:'yellow', shade:'light'}
];
$scope.myColor =  'red'; // red


<select ng-model="myColor" ng-options="color.name as color.name for color in colors">
  <option value="">-- choose color --</option>
</select>

+1 天
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics