0

I need to get array with ids when multi select box is submitted. The array should, then, look like this:

[13,14,15]

13,14,15 are ids inside objects...

here is what my select box looks like:

<select ng-model="groups.group" multiple="multiple" class="form-control ng-pristine ng-valid ng-touched" ng-options="group as group.name for group in groups.groups">
<option value="object:13" label="Group4">Group4</option>
<option value="object:14" label="Group6">Group6</option>
<option value="object:15" label="Group7">Group7</option>
</select>

Here is my angular code inside template:

<select ng-model="groups.group" multiple="multiple" class="form-control" ng-options="group as group.name for group in groups.groups">

1 Answer 1

1

var app = angular.module('myApp', []);

app.controller('appCtrl', function($scope) {
  $scope.groups = [1, 2, 3, 4, 5];
  $scope.selectedGroups = [];
  $scope.addedGroups = [];

  $scope.add = function() {
    $scope.addedGroups = $scope.selectedGroups;
  };
});
select,
div {
  width: 300px;
}
div {
  background-color: yellow;
  display: block;
  height: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="appCtrl">
  <select multiple="multiple" ng-model="selectedGroups">
    <option ng-repeat="group in groups" value="{{group}}">{{group}}</option>
  </select>
  <button ng-click="add()">add to box</button>
  <div>{{addedGroups}}</div>
  {{selectedGroups}}
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.