2016-04-11 9 views
1

this code penを使用して、私のIonicアプリケーションで「swipebale」カードのスタックを作成しています。 私はそれにいくつかの変更を加えたいと思います。私は 2)私は、それぞれの終わりに戻すためにカードをスワイプしたい代わりに「ダウン」の「アップ」トンネルビューを逆にしたい)Ionic Tinderカード2スタックの最後にカードを返す

picture

1:

今、私はこれを持っていますスタック(破棄されるのではなく)。

誰かが私にどこから始めたらいいか分かります。これに

   <div class="discard" ng-click="onClickTransitionOut(card)">DISCARD</div> 
      <img ng-src="{{ card.image }}"> 
     </div> 
     </td-card> 

: は、私が "廃棄" 機能に変更

<div class="discard" ng-swipe-left="cardSwipedLeft(card)">DISCARD</div> 
      <img ng-src="{{ card.image }}"> 
     </div> 

をしかし、スワイプは動作しません。

<ion-pane ng-controller="CardsCtrl" class="background-grey"> 

    <!-- ************************* 
    TD Cards 
    - We start off with an ng-if so that the cards are not generated 
     unless $scope.cards is not 'null' 
    ************************* --> 
    <div> 
    <td-cards> 
     <td-card ng-repeat="card in cards.active" on-swipe-left="cardSwipedLeft($index)" on-swipe-right="cardSwipedRight($index)"> 
     <div class="image" ng-controller="CardCtrl"> 
      <img ng-src="{{ card.image }}"> 
     </div> 
     </td-card> 

    </td-cards> 
    </div> 

</ion-pane> 

そしてJS

: そして、私はここでUPDATE

が全体のコントローラである。この

 $scope.$on('removeCard', function(event, element, card) { 
    var discarded = $scope.cards.master.splice($scope.cards.master.indexOf(card), 1); 
    $scope.cards.discards.push(discarded); 
    }); 

    $scope.cardSwipedLeft = function(index) { 
    console.log('LEFT SWIPE'); 
    var card = $scope.cards.active[index]; 
    $scope.cards.push(card); 
    }; 
    $scope.cardSwipedRight = function(index) { 
    console.log('RIGHT SWIPE'); 
    var card = $scope.cards.active[index]; 
    $scope.cards.push(card); 
    }; 

}) 

enter image description here

removeCard機能を変更しました

.controller('CardsCtrl', function($scope, TDCardDelegate, $timeout) { var cardTypes = [ { image: 'img/cards/ASE card.png' }, { image: 'img/cards/EDP card.png' }, { image: 'img/cards/R2A card.png' }, { image: 'img/cards/WTR card.png' }, { image: 'img/cards/RRH card.png' }, { image: 'img/cards/Staffing.png' }, { image: 'img/cards/Intercontrat.png' } ]; $scope.cards = { master: Array.prototype.slice.call(cardTypes, 0), active: Array.prototype.slice.call(cardTypes, 0), } $scope.cardDestroyed = function(index) { $scope.cards.active.splice(index, 1); }; $scope.addCard = function() { var newCard = cardTypes[0]; $scope.cards.active.push(angular.extend({}, newCard)); } $scope.$on('removeCard', function(event, element, card) { $scope.cards.push(card); }); $scope.cardSwipedLeft = function(index) { console.log('LEFT SWIPE'); var card = $scope.cards.active[index]; $scope.cards.push(card); }; $scope.cardSwipedRight = function(index) { console.log('RIGHT SWIPE'); var card = $scope.cards.active[index]; $scope.cards.push(card); }; }) .controller('CardCtrl', function($scope, TDCardDelegate) { }); 
+0

あなたが参照として全体のカードオブジェクトに渡しているように見えるあなたが見ているものを誤り、ないインデックスは... NG-スワイプ左 '使用=「cardSwipedLeft($インデックス)」'代わり – Pogrindis

+0

私は"ジェスチャーが定義されていません" – Hana

+0

'ngTouch'モジュールをインストールする必要があります:https://docs.angularjs.org/api/ngTouch – Pogrindis

答えて

0

したがって、イオンのジェスチャーを使用しているときは、独自の指令を適用する必要があります。

あなたは、イオンのジェスチャーに ng-swipe-leftを交換する必要があり、あなたのHTMLで

:そうのようOnSwipe

<div class="discard" on-swipe-left="cardSwipedLeft($index)">DISCARD</div> 
      <img ng-src="{{ card.image }}"> 
     </div> 

これは、イオン性によって定義されたジェスチャーを使用します。

+0

私はまだ上記の図で述べたのと同じエラーがあります。最初のカードだけがスワイプされます。その後、それは "ジェスチャーは定義されていません" – Hana

+0

他のジェスチャーを添付しましたか?たぶん、あなたは 'スワイプ右'浮遊しているのでしょうか? – Pogrindis

+0

投稿者にコントローラ全体を追加しました – Hana

0

トンネルビューを逆にする方法はわかりませんが、各カードを廃棄する代わりにスタックの最後に戻す方法は次のとおりです。少なくともこれが役立つことを願っています。

$scope.cardDestroyed = function(index) { 
    var loTopCard = $scope.cards.active[index]; 
    $scope.cards.active.splice(index, 1); 
    console.log('Card Count after Remove ' + $scope.cards.active.length); 
    $scope.cards.active.push(loTopCard); 
    console.log('Card Count after add ' + $scope.cards.active.length); 

    }; 
関連する問題