1

I'm loading data from a database and save it to an array as follows:

$scope.allGroups = [{id: 1, groupName: group1}, {id: 2, groupName: group2}, ..]

In my view, I'm trying to select multiple group names as follows:

<div
  class="drag-container avaliable-groups-connect groups-container schedule-container"
>
  <div class="group" ng-repeat="m in allGroups">
    <input type="checkbox" ng-model="m.selected" />
    <span>{{ m.groupName }}</span>
  </div>
</div>

I want to save selected items (m.selected) to an array one-by-one and bind that array to ng-model="schedule.selectedGroups"

How can I perform that? Thank you..

1 Answer 1

0
<div class="group" ng-repeat="m in allGroups" ng-init="m.selected = false">
   <input type="checkbox" ng-model="m.selected" />
   <span>{{ m.groupName }}</span>
</div>

Now your checkbox ng-model with modify the variable to true or false and in your js code you can do like below.

$scope.schedule.selectedGroups = $scope.allGroups.filter(function (data) {
     return data.selected === true;
});
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.