Currently, I am fetching data from a WebAPI and then storing it in an array called products, which is scoped.
$scope.products
In addition to the products array, I also have another scoped array named selectedFish.
$scope.selectedFish = [];
My objective is to locate a specific product within the products array, make modifications to it, and subsequently add it to the selectedProducts array.
Within the same controller, I have implemented the following function:
// Function to add a new fish to the selectedFish array
$scope.add = function() {
// Locate existing fish from the products list
var newFishToAdd = $filter('filter') ($scope.products, { Id: $scope.selectedProduct });
// Modify the name property
newFishToAdd[0].FishName = $scope.selectProductName;
// Add the new fish to the selected fish array
$scope.selectedFish.push(newFishToAdd[0]);
$scope.bindModel();
}
While this approach does work, I am encountering issues when attempting to add the same product multiple times with different FishName values. It seems to update all entries in the array for the same selectedProduct with the last entered FishName value.