0

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();
  };
});
1
  • I don't see how this has anything to do with Angular. Commented Apr 11, 2014 at 16:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.