即使使用ng-selected也获得空白下拉值

时间:2019-04-03 07:33:52

标签: javascript html angularjs

我正在使用ng-selected从下拉列表中获取选定的值。但是相反,它显示为空白。

我尝试了以下代码:

<div>
   <select id="user_org" ng-model="selectedorg.allValue" ng-change="qrochange(this)" material-select watch required >
           <option ng-selected='{{selectedorg.allValue == user.user_org}}' ng-repeat="user in orgowners | unique:'user_org'" value="{{user.id}},{{user.user_org_quota}}">{{user.user_org}}</option>
   </select>
   <label for="user_org">Organization</label>
</div>

Controller.js:

var orgowners = Restangular.one("users/" + user_id + "/list");
            orgowners.getList().then(function(projects) {
                $scope.orgowners = projects;
                 var parent_index = $scope.findIndexByKeyValue($scope.orgowners,'id',$scope.id);
                    $scope.selectedorg= $scope.orgowners[parent_index];
                    $scope.selectedorg.allValue = $scope.selectedorg.id+','+$scope.selectedorg.user_org_quota;
                    $scope.qro = $scope.selectedorg.user_org_quota;
            })

        $scope.qrochange = function(event) {
                id = event.selectedorg.allValue;
                var quota_res = id.split(',')[1];
                $scope.qro = quota_res;
                $scope.user_org_quota = parseInt(quota_res);
            }

如何获取所选值?

1 个答案:

答案 0 :(得分:0)

ng-model应该提供选定的值。

呈现下拉菜单的一种更简便的方法是使用ng-options。像这样:

<select ng-model="selectedorg" ng-options="user.user_org for user in orgowners | unique:'user_org'">

另请参阅:angularjs ngOptions