2016-09-14 4 views
0

名前のリストにチェックされた名前だけを取得しようとしています。ここに私のコードモデルは以下のとおりです。<複数選択>でのみチェックされます

<select ng-model="selectTopic" ng-change="changedTopic(selectTopic)" ng-options="option as option for option in topics">> 
 
    <option value="" disabled>Select a Subject</option> 
 
</select> 
 

 
<select ng-model="selectDept" ng-change="changedDepartment(selectDept)" ng-options="option as option for option in department"> 
 
    <option value="" disabled>Select a Department</option> 
 
</select> 
 
\t \t \t \t 
 
<select ng-model="selectUser" ng-options="option as option for option in users" multiple="multiple"> 
 
\t <option value="" disabled>Select a User</option> 
 
</select>

私が選択したトピック、部門、およびユーザーを取得したいです。私は現在使用しています:console.log($ scope.topics + $ scope.departments + $ scope.users)しかし、すべてを返します。私は選択したアイテムを返すだけです。

誰でもお手伝いできますか?

+1

選択した項目は、ng-modelディレクティブを使用してバインドされた変数で使用できます –

答えて

1

あなたがいない配列、NG-モデルを印刷する必要があります。

console.log($scope.selectTopic); 
console.log($scope.selectDept); 
console.log($scope.selectUser); 

はそれが=をホープ)

0

使用フォームでのモデルのための1つのオブジェクト、あなたはすべてのユーザー入力を持っていますサーバーに送信するか、この作業が一時的に

ビューに次のように入れて見てフォーム

$scope.userInput={} 

<select ng-model="userInput.selectTopic" ng-change="changedTopic(userInput.selectTopic)" ng-options='...'> 
<select ng-model="userInput.selectDept" ng-change="changedDepartment(userInput.selectDept)" ng-options='...'> 

をリセットすることが簡単になり、1つのオブジェクトで

<pre>{{userInput|json}}</pre> 
関連する問題