获取ng-option中所选项目的ID

时间:2016-05-27 13:51:03

标签: angularjs angular-ngmodel ng-options

我想获取所选项目的ID,但console.log显示 undefined

查看

 <select ng-change="test()" ng-model="selectedone" ng-options="item.id as item.pseudo for item in friends"></select>

控制器

  $scope.test = function(){
        console.log($scope.selectedone);
    }

1 个答案:

答案 0 :(得分:3)

以下是正在运行的代码:

视图:

 <select ng-change="test(selectedId)" ng-model="selectedId" ng-options="id.id as id.pseudo for id in idList"> </select>

控制器:

  $scope.test = function(selectedId) {
            alert(selectedId);
        }