angularjscarouselbootstrap-carousel

How do I show all indicators for carousel in an ng-repeat?


I have several slides and I'm able to show all indicators if I simply enumerated them similar to the example in here: https://www.w3schools.com/bootstrap/bootstrap_carousel.asp.

However, the number of slides is dynamic that's why I am using ng-repeat. I'm trying to show all the indicators in my carousel but it only shows 1 indicator for the active slide.

enter image description here

Here's the HTML of my AngularJS directive.

<div class="container slide" id="myCarousel" data-interval="{{carouselVM.interval }}" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators" ng-repeat="curItem in carouselVM.data">
        <li data-target="#myCarousel" data-slide-to="$index" ng-class="{'active': $index == 0}"></li>
    </ol>
    <!-- Wrapper for slides -->
    <div class="carousel-inner">
        <div class="item" style="background-image: url(&quot;{{curItem.image}}&quot;);" ng-repeat="curItem in carouselVM.data" ng-class="{'active' : !$index}">
            <div class="item-headline" ng-bind-html="curItem.description">
            </div>
        </div>
    </div>

    <!-- Left and right controls -->
    <a class="left switch-button" href="#myCarousel" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left fa fa-angle-left"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="right switch-button" href="#myCarousel" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right fa fa-angle-right"></span>
        <span class="sr-only">Next</span>
    </a><br>
</div>

How do I show all indicators on every slide?


Solution

  • I got what I need. The ng-repeat needs to happen in the <li> not the <ol>.

    <div class="container slide" id="myCarousel" data-interval="{{carouselVM.interval }}" data-ride="carousel">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="$index" ng-class="{'active': $index == 0}" ng-repeat="curItem in carouselVM.data"> </li>
        </ol>
        <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <div class="item" style="background-image: url(&quot;{{curItem.image}}&quot;);" ng-repeat="curItem in carouselVM.data" ng-class="{'active' : !$index}">
                <div class="item-headline" ng-bind-html="curItem.description">
                </div>
            </div>
        </div>
    
        <!-- Left and right controls -->
        <a class="left switch-button" href="#myCarousel" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left fa fa-angle-left"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right switch-button" href="#myCarousel" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right fa fa-angle-right"></span>
            <span class="sr-only">Next</span>
        </a><br>
    </div>