I am struggling with the following code:
app.controller('modalController', function($scope, $http,$modalInstance, $rootScope, items){
// Retrieving information
$http.post('/ajax/bundle', {'items':items}).success(function(data){
$scope.info = data['info'];
});
// [BUTTON] Add Bundle
$scope.selectBundle = function() {
// Adding info to the cart
$rootScope.cart.push($scope.info);
// Simplified info
$rootScope.selectedBundle.push(items)
// Closing the modal
$modalInstance.close();
}
// [BUTTON] Remove bundle
$scope.removeBundle = function() {
// Iterating through all selected bundles
angular.forEach($rootScope.selectedBundle,function(value, key){
// Checking if exists
if (angular.equals(value,items)) {
// Removing from simplified info
$rootScope.selectedBundle.splice($rootScope.selectedBundle.indexOf(value), 1);
// removing from cart
// $rootScope.cart.splice($rootScope.cart.indexOf($scope.info), 1);
}
});
// Closing the modal
$modalInstance.close();
}
});
After using:
console.log($rootScope.cart);
console.log($scope.dados);
console.log($rootScope.cart.indexOf($scope.dados));
the console logs the correct position within $scope.selectBundle.
However, when used in $scope.removeBundle, it always returns -1 indicating that it's not found. Can anyone provide some guidance or help me troubleshoot this issue?