Austin Hunter Austin Hunter - 2 months ago 5
AngularJS Question

Get Checked Only in <Select multiple>

I am trying to get only the checked names in a list of names. Here is my code model:



<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>

<select ng-model="selectUser" ng-options="option as option for option in users" multiple="multiple">
<option value="" disabled>Select a User</option>
</select>





I want to get the selected topic, department, and users. I am currently using: console.log($scope.topics + $scope.departments + $scope.users) but it returns everything. I just want to return the selected items.

Can anyone help me out?

Answer

You have to print the ng-models , not the arrays:

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

Hope it helps =)

Comments