我想创建一个多项滑块来列出使用ng-repeat(Angular 1.6)的一些玩家。我想在ul> lis中添加一个prev/next按钮来访问数组中的下一个或上一个播放器,逐个移动视图。在AngularJS中的多个项目中添加上一个/下一个按钮(ngRepeat)
HTML ---- sliderdemo.html
<div ng-controller="SliderDemoCtrl">
<div class="champions-slider">
<ul class="team-members list-inline text-center" style="display:flex" >
<li ng-repeat="player in players | limitTo: 4" style="padding:10px">
<div class="img-holder">
<a href="/player/{{ player.name }}"><img ng-src="{{ player.image }}" alt="{{player.name}}" width="20px"></a>
</div>
<strong class="name">{{ player.name }}</strong>
</li>
</ul>
<a href="#" class="btn-prev" ng-click="?????">Prev</a>
<a href="#" class="btn-next"ng-click="?????">Next</a>
</div>
</div>
我控制器JS --- slider.demo.controller.js
var myApp = angular.module('slider.demo', []);
myApp.controller('SliderDemoCtrl',['$scope',function($scope){
$scope.players = [
{
image:"http://placehold.it/500/e499e4/fff&text=1",
name: "tes 1"
},
{
image:"http://placehold.it/500/e499e4/fff&text=2",
name: "tes 2"
},
{
image: "http://placehold.it/500/e499e4/fff&text=3",
name: "tes 3"
},
{
image:"http://placehold.it/500/e499e4/fff&text=4",
name: "tes 4"
},
{
image:"http://placehold.it/500/e499e4/fff&text=5",
name: "tes 5"
},
{
image: "http://placehold.it/500/e499e4/fff&text=3",
name: "tes 6"
}
];
}]);
这是问题的一个plunkr :https://plnkr.co/edit/J7dxeMfM22ju5gpZl5ri?p=preview
任何帮助将不胜感激。
Thx!
一个不需要太多代码更改的简单解决方案就是在'ng-repeat'中显示另一个数组。这个第二个数组在开始时将被前四个元素填充,并且您可以在'ng-click'中分配函数,以便添加和移除此数组上的元素,并使用整个数组中的值填充它。编辑:因为角1.4,似乎你也可以使用开始值'limitTo:length:start' – Kaddath
你是否在寻找类似https://plnkr.co/edit/hAE6o0rUx0Jzm4MmRzLZ?p=preview或者你想要它圆? – Vivz