Four items in bootstrap carousel Ng repeat?

自古美人都是妖i 提交于 2020-01-05 05:51:28

问题


I am trying to display four items in a slide. But how do I repeat it the main row, because it uses an active class for the active slide. This is how my HTML looks.

<div class="carousel slide" id="myCarousel">
        <div class="carousel-inner">
            <div class="item active">
                <div class="row">
                    <div class="col-xs-3" ng-repeat="image in images"><a href="#"><img ng-src="{{image}}" class="img-responsive"></a></div>
                </div>
            </div>
        </div>
        <a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
    </div>

And an example of the JSON.

$scope.images = [
"http://placehold.it/500/e499e4/fff&amp;text=1",
"http://placehold.it/500/e499e4/fff&amp;text=2",
"http://placehold.it/500/e499e4/fff&amp;text=3",
"http://placehold.it/500/e499e4/fff&amp;text=4",
"http://placehold.it/500/e499e4/fff&amp;text=5",
"http://placehold.it/500/e499e4/fff&amp;text=6",
"http://placehold.it/500/e499e4/fff&amp;text=7",
]

回答1:


One way you can do it is divide the array in chunks...

<div class="item active">
    <div class="row">
        <div class="col-xs-3" ng-repeat="image in images.slice(0,4)"><a href="#"><img ng-src="{{image}}" class="img-responsive"></a></div>
    </div>
</div>
<div class="item">
    <div class="row">
        <div class="col-xs-3" ng-repeat="image in images.slice(5,9)"><a href="#"><img ng-src="{{image}}" class="img-responsive"></a></div>
    </div>
</div>

Demo



来源:https://stackoverflow.com/questions/43054197/four-items-in-bootstrap-carousel-ng-repeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!