This first pass, in my opinion, will work for you. I am in the process of creating a test page to check the accuracy and update the modified result, which I hope will not be.
EDIT: I ran it and it seems to have done what you want if I understood the problem correctly. There were a few syntax errors that I edited.
Here's a tablet with a condensed, cleaned code http://plnkr.co/edit/K7XuMu?p=preview
HTML
<button ng-click="transferArrays(objects, appliedObjects)">Add</button> <button ng-click="transferArrays(appliedObjects, objects)">Remove</button>
Js
$scope.transferArrays = function (arrayFrom, arrayTo) { var selectedElements; selectedElements = []; angular.forEach(arrayFrom, function(element) { if (element.isSelected) { element.isSelected = false; selectedElements.push(element); } }); angular.forEach(selectedElements, function(element) { arrayTo.push(arrayFrom.splice( arrayFrom.map(function(x) { return x.uniqueId; }) .indexOf(element.uniqueId), 1)); }); };
Old code
$scope.remove = function () { var selectedElements; selectedElements = []; angular.forEach($scope.appliedObjects, function (element) { if (element.isSelected) { element.isSelected = false; selectedElements.push(element); } }); angular.forEach(selectedElements, function (element) { $scope.objects.push($scope.appliedObjects.splice( $scope.appliedObjects.map(function (x) { return x.uniqueId; }) .indexOf(element.uniqueId), 1)); }); }; $scope.add = function () { var selectedElements; selectedElements = []; angular.forEach($scope.objects, function (element) { if (element.isSelected) { element.isSelected = false; selectedElements.push(element); } }); angular.forEach(selectedElements, function (element) { $scope.appliedObjects.push($scope.objects.splice( $scope.objects.map(function (x) { return x.uniqueId; }) .indexOf(element.uniqueId), 1)); }); };
source share