私はAngularJSにかなり慣れていないので、単純な間違いを犯していると確信しています。
ng-repeat インデックスを考慮できるようにvar newCard = cardTypes.shift();
、使用するのではなく、行に cardTypes 配列をスプライスしたいと考えています。.shift()
で問題なく動作し.shift()
ますが、試してもデータがまったく届きません.splice(index, 1)
。
どんな助けでも大歓迎です。
.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();
};
});