app.controller('ShoppingCartPageController',['$scope','$window','$timeout',function($scope,$window,$timeout){ var firebaseShoppingCart = firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('shoppingCart'); $scope.shoppingCartItems = {}; firebaseShoppingCart.on('value',function(snap){ $scope.shoppingCartItems = snap.val(); }) // funcitons $scope.totalPrice = function(){ $scope.total = 0; angular.forEach($scope.shoppingCartItems,function(item){ $scope.total += item.overallPrice; }) return $scope.total; } $scope.removeItem = function(i){ // var shoppingCartFooter = document.querySelector('shopping-cart-page .items-footer'); // var shoppingCartItem = document.querySelector('.shopping-cart-page .item'); // var shoppingCartItemHeight = $window.getComputedStyle(shoppingCartItem, null).getPropertyValue('height'); // shoppingCartFooter.style.transform = 'translateY(-'+shoppingCartItemHeight+')!important'; // var shoppingCartFooterJQ = angular.element(document.querySelector('.shopping-cart-page .items-footer')); // shoppingCartFooterJQ.addClass('shopping-cart-footer-animate'); // $timeout(function(){ // shoppingCartFooterJQ.removeClass('shopping-cart-footer-animate'); // },1000) var keys = Object.keys($scope.shoppingCartItems); delete $scope.shoppingCartItems[keys[i]]; firebaseShoppingCart.set($scope.shoppingCartItems); } $scope.orderSuccess = false; $scope.checkOut = function(){ firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('userDiets').set($scope.shoppingCartItems); firebaseShoppingCart.set({}); $scope.orderSuccess = true; } }])