angular.module('starter.controllers', [])

.controller('AccountCtrl', function($scope) {
})

.directive('noScroll', function($document) {

  return {
    restrict: 'A',
    link: function($scope, $element, $attr) {

      $document.on('touchmove', function(e) {
        e.preventDefault();
      });
    }
  }
})

.controller('DashCtrl', function($scope, $http, $localstorage,TDCardDelegate) {
  var cardTypes;

  $scope.cardDestroyed = function(index) {
    $scope.cards.splice(index, 1);
    // $scope.addCard();
    console.log('destroyed');
  };

  $scope.addCard = function() {

    var newCard = cardTypes.splice(Math.floor(Math.random() * cardTypes.length),1)[0];
    //newCard.id = Math.random();
    console.log('new card is', newCard);
    $scope.cards.push(angular.extend({}, newCard));
  }

  $scope.startExplore = function() {
    console.log($localstorage.getObject('temp'));

    if(Object.keys($localstorage.getObject('temp')).length ===0){
      console.log('making a http request');
      $http.get("https://mealmatch2.herokuapp.com/test/explore").success(function(data, status, headers, config) {
        console.log('success', data);
        cardTypes = data;
        $scope.cards = Array.prototype.slice.call(cardTypes, 1,4);
        $localstorage.setObject('temp', data);
      })
      .error(function(data, status, headers, config) {
      console.log('fail', data);
      }); 
    } else{ //currently pulling from local storage data to avoid overusing api

      //make a copy of local storage so that local storage remains persistant
      cardTypes = Array.prototype.slice.call($localstorage.getObject('temp'));
      //load 3 cards for view
      $scope.cards = Array.prototype.splice.call(cardTypes, 1,4);
    }
  };

  $scope.startExplore();
})

.controller('CardCtrl', function($scope, TDCardDelegate) {
  $scope.cardSwipedLeft = function(index) {
    console.log('LEFT SWIPE');
    $scope.addCard();
  };
  $scope.cardSwipedRight = function(index) {
    console.log('RIGHT SWIPE');
    $scope.addCard();
  };
})

.filter('largerimages', function () {
  console.log('this ran');
    return function (item) {
      return item.replace('s90', 's450');  
    }
  });

@@ -383,20 +383,29 @@
 Delegate
+,$timeout
 ) %7B%0A
-
   var ca
@@ -496,33 +496,8 @@
 1);%0A
-    // $scope.addCard();%0A
     
@@ -522,16 +522,48 @@
 oyed');%0A
+    $timeout($scope.addCard,0);%0A
   %7D;%0A%0A  
@@ -684,18 +684,16 @@
 0%5D;%0A    
-//
 newCard.
@@ -1246,25 +1246,25 @@
 ardTypes, 1,
-4
+1
 );%0A        $
@@ -1738,17 +1738,17 @@
 ypes, 1,
-4
+1
 );%0A    %7D
@@ -1912,32 +1912,35 @@
 EFT SWIPE');%0A   
+ //
  $scope.addCard(
@@ -2024,19 +2024,22 @@
 WIPE');%0A
-
    
+ //
  $scope.

add card on destroy instead of swipe left/right