I'm pretty new to AngularJS so I'm sure I'm just making a simple mistake.
I want to splice the cardTypes array on the var newCard = cardTypes.shift();
line rather than using .shift()
so I can take account of my ng-repeat index.
It works fine with .shift()
but no data comes through at all if I try .splice(index, 1)
.
Any help would be greatly appreciated.
.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();
};
});
Are you talking about the addCard function?
There isn't an 'index' variable in that function so maybe you meant to do
.splice(0, 1); to remove the first one?
Adding 'use strict'; to the top of all my javascript files has helped me catch problems like that.