Being fairly new to the world of AngularJS, I suspect that I am just making a simple mistake.
My goal is to splice the cardTypes array at the var newCard = cardTypes.shift();
line rather than using .shift()
so that I can consider my ng-repeat index.
While it works perfectly fine with .shift()
, no data comes through at all when I attempt to use .splice(index, 1)
.
I would greatly appreciate any assistance provided.
.controller('CardsCtrl', function($scope, $ionicSwipeCardDelegate) {
var cardTypes = [
{ title: 'Swipe down to clear the card', image: 'img/pic.png' },
{ title: 'Where is this?', image: 'img/pic.png' },
{ title: 'What kind of grass is this?', image: 'img/pic2.png' },
{ title: 'What beach is this?', image: 'img/pic3.png' },
{ title: 'What kind of clouds are these?', image: 'img/pic4.png' }
];
$scope.cards = Array.prototype.slice.call(cardTypes, 0, 0);
$scope.cardSwiped = function(index) {
$scope.addCard();
};
$scope.cardDestroyed = function(index) {
$scope.cards.splice(index, 1);
$scope.addCard();
};
$scope.addCard = function() {
var newCard = cardTypes.shift();
newCard.id = Math.random();
$scope.cards.push(angular.extend({}, newCard));
}
})
.controller('CardCtrl', function($scope, $ionicSwipeCardDelegate) {
$scope.goAway = function() {
var card = $ionicSwipeCardDelegate.getSwipebleCard($scope);
card.swipe();
};
});