angular-swing icon indicating copy to clipboard operation
angular-swing copied to clipboard

How to dynamically add card to stack?

Open m10l opened this issue 10 years ago • 4 comments

I'm creating an initial stack of cards and want to add a new card at the bottom of the stack to replace a card that has been thrown out. Is there a way of achieving this?

Here is the function I'm using. Currently cards are being added at the top of the stack. Using $scope.stack.push instead of unshift also produces the same result.

$scope.addCard = function(name) {
  $scope.stack.unshift({
    'name': name
  });
};

m10l avatar Feb 25 '15 17:02 m10l

This works for me:

$scope.friends.unshift(friend);

shprink avatar May 07 '15 23:05 shprink

I tried the same as @m10l mentioned, tried with push and also with unshift - it does not work

hirbod avatar May 08 '16 21:05 hirbod

I found out, that it was because of "track by card.uid". Changed to "track by $index" - now it works as intended!

hirbod avatar May 10 '16 11:05 hirbod

Track by $index and $scope.apply() helped me.

romankierzkowski avatar Oct 23 '16 18:10 romankierzkowski