Austin Hunter Austin Hunter - 1 year ago 58
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 ng-model="selectDept" ng-change="changedDepartment(selectDept)" ng-options="option as option for option in department">
<option value="" disabled>Select a Department</option>

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

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 Source

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


Hope it helps =)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download