2016-05-31 5 views
0

私のようなオブジェクト要素のリストを持っている:クリックでオブジェクトを繰り返したり、anglejを使ってスワイプする方法はありますか?

$scope.products = [ 
    { 
     name: 'First News Heading', 
     content: 'Lorem ipsum', 
     cover: 'img/img1.jpg' 
    }, 
    { 
     name: 'Second News Heading', 
     content: 'The veldt fox. Bright vixens jump; dozy fowl quack. Quick wafting zephyrs vex bold Jim.', 
     cover: 'img/img2.jpg' 
    }, 

]; 

そして、私は次のようにその後、表示したい:一緒にNG-リピートディスプレイにそれらのすべてを使用して

<div class="thumbnail"> 
    <img ng-src="{{ product.cover }}"> 
     <p class="title">{{ product.name }}</p> 
     <p class="content">{{ product.content }}</p> 
</div> 

。次の要素を表示するには、クリックまたはスワイプを使用します。

+3

私はあなたがcarousel.httpsを探していると思う://github.com/angular-ui/bootstrap/tree/master/src /カルーセル – brk

+0

plsはあなたのngリピートテンプレートを追加します – azad

+0

サムネイルdivはng-repeatテンプレートです – startCoding

答えて

0

次のことを試してみてください。

<div class="thumbnail"> 
    <img ng-src="{{product.cover}}"> 
    <p class="title">{{product.name}}</p> 
    <p class="content">{{product.content}}</p> 
</div> 
<input type="button" ng-click="previous()" value="Previous" /> 
<input type="button" ng-click="next()" value="Next" /> 

JS:

$scope.currentPosition=0; 
$scope.product=$scope.products[0]; //initialize the product var with first element 
$scope.next=function(){ 
    $scope.currentPosition++; 
    if($scope.currentPosition <$scope.products.length) 
     $scope.product=$scope.products[$scope.currentPosition]; 
    else 
     $scope.curentPosition=$scope.products.length-1; 
} 
$scope.previous=function(){ 
    $scope.currentPosition--; 
    if($scope.currentPosition >=0) 
     $scope.product=$scope.products[$scope.currentPosition]; 
    else 
     $scope.curentPosition=0; 
} 
+0

うまく動作します。ありがとうございました。 – startCoding

関連する問題