Move items from 1 list to another list AngularJS
HTML
<div ng-app>
<div ng-controller="MainController">
<div></div>
<div style="margin-left:90px;">
<table>
<tr style="height:35px;margin-bottom:10px;">
<tr>
<input type="text" ng-model="search" placeholder="Search..." />
<td style="background-color:#666699"><span style="margin-left:5px;color:white;background-color:#666699;width:250px;">Available</span>
</td>
<td></td>
<td style="background-color:#666699"><span style="margin-left:5px;color:white;background-color:#666699;width:250px;">Selected</span>
</td>
<tr>
<tr>
<td>
<div>
<select multiple id="availabelist" size="10" style="width:275px" ng-change="OnAvailableChange()" ng-model="SelectedAvailItems" ng-options="i as i.email for i in AvailableListItems[selectFaIndex] | filter:search | orderBy:'email'"></select>
</div>
</td>
<td>
<div style="float:left">
<input id="btnRight" type="button" value="-->" style="width:50px" ng-click="btnRight()" />
<br/>
<br/>
<input id="btnLeft" type="button" value="<--" style="width:50px" ng-click="btnLeft()" />
</div>
</td>
<td>
<div>
<select multiple id="selectedlist" size="10" style="width:275px" ng-model="SelectedSelectedListItems" ng-options="i as i.email...
JavaScript
function MainController($scope) {
$scope.selectFaIndex;
$scope.SelectedAvailItems = [];
$scope.SelectedSelectedListItems = [];
$scope.SelectedListItems = [
[]
];
$scope.AvailableListItems = [
[]
];
$scope.DefaultListItems = [
[{
email: '[email protected]'
}, {
email: '[email protected]'
}, {
email: '[email protected]'
}],
[{
email: '[email protected]'
}, {
email: '[email protected]'
}, {
email: '[email protected]'
}],
[{
email: '[email protected]'
}, {
email: '[email protected]'
}, {
email: '[email protected]'
}]
];
angular.copy($scope.DefaultListItems, $scope.AvailableListItems);
$scope.btnRight = function () {
//move selected.
angular.forEach($scope.SelectedAvailItems, function (value, key) {
this.push(value);
}, $scope.SelectedListItems[$scope.selectFaIndex]);
//remove the ones that were moved.
angular.forEach($scope.SelectedAvailItems, function (value, key) {
for (var i = $scope.AvailableListItems[$scope.selectFaIndex].length - 1; i >= 0; i--) {
if ($scope.AvailableListItems[$scope.selectFaIndex][i].email == value.email) {
$scope.AvailableListItems[$scope.selectFaIndex].splice(i, 1);
}
}
});
$scope.SelectedAvailItems = [];
};
$scope.btnLeft = function () {
//move selected.
angular.forEach($scope.SelectedSelectedListItems, function (value, key) {
this.push(value);
}, $scope.AvailableListItems[$scope.selectFaIndex]);
//remove the ones that were moved from the source container.
angular.forEach($scope.SelectedSelectedListItems, function (value, key) {
for (var i =...