正文  电脑教程 > 服务器教程 >

angular select 默认值如何设置

如下所示: <select ng-model="selected" ng-options="x.id as x.name for x in user...

如下所示:

<select ng-model="selected" ng-options="x.id as x.name for x in users"></select>
$scope.users = [
    {name:‘a‘,id:‘1‘},
    {name:‘b‘,id:‘2‘},
    {name:‘c‘,id:‘3‘}
  ];
  $scope.selected=‘2‘;//id的值,区分类型
  $scope.selected=$scope.users[0].id;//如果想要第一个值