I have a big list containing all of my data, and I have another shorter list containing only the selected data. Originally, all the data is selected so both lists are identi
Please check with this code and let me know whether it solves your issue. Also please check this working plnkr of your example scenario.
Template:
Controller:
$scope.update_selected_Brain_regions = function (region) {
for (var i = 0; i < $scope.brain_regions.length; i++) {
var current_region = $scope.brain_regions[i];
if (current_region.id === region.id) {
if (region.show) {
$scope.selected_brain_regions.push(current_region);
} else {
var index = $scope.selected_brain_regions.map(function(x){ return x.id; }).indexOf(current_region.id);
$scope.selected_brain_regions.splice(index,1);
}
}
}
};