2016-05-10 9 views
0

私のコントローラーで使用するために私のすべての結果から選択したいと思っています。コントローラーの複数選択オプションから値を取得する方法

<div class="form-group" ng-repeat="att in arr track by $index" ng-hide="check"> 
    <div class="col-md-3"> 
     <label for="phone">{{att.name}}</label> 
    </div> 
    <div class="col-md-9"> 
     <select class="form-control" ng-model="user.charactValue" multiple="true"> 
      <option ng-repeat="itemss in att.value track by $index" value="{{itemss}}" >{{itemss}}</option> 
     </select> 
     <div class="text-center"><a data-toggle="modal" data-target="#addNewCharacteristic" ng-click="getObj(att)">Добави</a></div> 
    </div> 
</div> 
<input type="submit" ng-click="companyBusinessAsset"> 

$scope.companyBusinessAsset = function() { 
    console.log ($scope.charactValue); 
    // this return Undefined 
}; 

ダウンコードが使用されていますが、その都度入力されます。

$scope.charactValue = []; 

$scope.$watch ('selected', function(nowSelected) { 
    $scope.selectedValues = []; 
    console.log(nowSelected) 
    // this return Undefined 
    console.log('dddd') 
    if (!nowSelected) { 
     console.log("IFFFFFF"); 
     return; 
    } 
    angular.forEach ($scope.charactValue, function(val) { 
     console.log(val); 
     $scope.charactValue.push (val.id.toString()); 
    }); 
}); 

答えて

0

Iは、以下のように私のプロジェクトの一つでこれをやった、これが役に立てば幸い:

<select multiple="multiple" name="selectedRoleId" ng-model="user.selectedRole" class="form-control"> 
     <option ng:repeat="role in roleList" value="{{role.Name}}">{{role.Name}}</option> 
</select> 

コントローラに機能を提出するには:

//declare $scope.user to avoid undefined/notfound error 
$scope.user = {}; //above the function 
//and inside the function 
$scope.submitForm=function() { 
    var reguser = new models.register($scope.user); 
}; 

あなたが選択した複数の値を取得します$scope.userselectedRoleプロパティ

+0

このコードは動作しますが、ng-repeatには3つの複数選択オプションがあります。各選択には同じng-modelがあります。結果を1つの複数選択オプションでのみ取得します。 –

+0

ブラウザでfirebug/developerエクスプローラを使用して、select要素のid/ng-modelsを確認します。彼らはお互いにユニークでなければならない –

1

selectng-multiple="true"を追加してみてください。

+0

私はNG-複数= 『true』を追加することが、私のオプションはСтилиянГеоргиев嘆願@スタンダールオプション –

+0

になりましたこの例を見てください:http://jsfiddle.net/Arg0n/TXPJZ/1607/ – Arg0n

+0

この作品はhtmlで印刷されますが、私のコントローラには未定義のものがありません。 –

関連する問題