28

I want to use bootstrap carousel along with angular js to display images in carousel content. But, when the navigation links clicked, it displays blank page.

My code sample is as follows. (Note : This code works well only with Bootstrap 3.1.0 but not along with AngularJS 1.2.13)

<div id="Carousel" class="carousel slide">
    <ol class="carousel-indicators">
        <li data-target="Carousel" data-slide-to="0" class="active"></li>
        <li data-target="Carousel" data-slide-to="1"></li>
        <li data-target="Carousel" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
        <div class="item active">
            <img src="images/c.png" class="img-responsive">
        </div>
        <div class="item">
            <img src="images/b.png" class="img-responsive">
        </div>
        <div class="item">
            <img src="images/a.png" class="img-responsive">
        </div>
    </div>
    <a class="left carousel-control" href="#Carousel" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#Carousel" data-slide="next">
       <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
</div>
Rakesh
  • 281
  • 1
  • 3
  • 5
  • did you remember to include jquery before bootstrap.js? – Chen-Tsu Lin Feb 20 '14 at 12:51
  • Yes. I have added it before bootstrap.js. – Rakesh Feb 20 '14 at 13:04
  • could you add a jsfiddle or plnkr to demo this problem? – Chen-Tsu Lin Feb 20 '14 at 13:06
  • Following link is my demo. http://plnkr.co/edit/IVw6tSxi0VjhT2ppnaDZ?p=preview **Source** : I have used the demo code from the link http://scotch.io/tutorials/javascript/single-page-apps-with-angularjs-routing-and-templating & modified it – Rakesh Feb 21 '14 at 11:15
  • 1
    they're really asking a lot I think, when you have to jump through hoops like this just to use a Bootstrap component which JUST WORKS everywhere else. – Randy L Jun 11 '15 at 00:05

9 Answers9

71

Building on what rbanning said, instead of adding the event handler you can just, after replacing the anchor tags with span tags, replace the href attribute with a "data-target" attribute and bootstrap takes care of the rest.

Like so:

<div id="Carousel" class="carousel slide">
<ol class="carousel-indicators">
    <li data-target="Carousel" data-slide-to="0" class="active"></li>
    <li data-target="Carousel" data-slide-to="1"></li>
    <li data-target="Carousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
    <div class="item active">
        <img src="images/c.png" class="img-responsive">
    </div>
    <div class="item">
        <img src="images/b.png" class="img-responsive">
    </div>
    <div class="item">
        <img src="images/a.png" class="img-responsive">
    </div>
</div>
<span class="left carousel-control" data-target="#Carousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
</span>
<span class="right carousel-control" data-target="#Carousel" data-slide="next">
   <span class="glyphicon glyphicon-chevron-right"></span>
</span>
</div>
chestermano
  • 853
  • 6
  • 12