I am getting data from a WebAPI and storing it in a scoped variable array products.
$scope.products
I also have a second scoped array
$scope.selectedFish = [];
What I am trying to do is find a product in the products array, modify it and add it into the selectedProducts array.
I have the following function declared on the same controller.
// Function to add a new fish to the selectedFish array
$scope.add = function() {
// Find existing fish from products list
var newFishToAdd = $filter('filter') ($scope.products, { Id: $scope.selectedProduct });
// Change the name property
newFishToAdd[0].FishName = $scope.selectProductName;
// Add new fish to the selected fish array
$scope.selectedFish.push(newFishToAdd[0]);
$scope.bindModel();
}
This does work, but I am having difficulty where if I add the same product twice with different FishName values, it updates all entries in the array for the same selectedProduct with the last FishName entered.
$scope.selectedFish.push(newFishToAdd[0]);use angular.copy for deep copying.