0

I've been trying to implement a bootstrap carousel in my angular web page. I got the source code from the bootstrap site, so I believe everything is set up right...

However, the carousel never actually slides. Also, when I click on the controls (prev & next) the whole page reloads and redirects me from http://localhost:4200/blogs to http://localhost:4200/#carouselExampleIndicators (where the carousel no longer appears). I'm not sure if this is a routing issue or what...


<div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-ride="carousel" >
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
      <div class="carousel-item active" data-interval="10000">
        <img class="img-fluid" src="https://img.webmd.com/dtmcms/live/webmd/consumer_assets/site_images/article_thumbnails/other/cat_relaxing_on_patio_other/1800x1200_cat_relaxing_on_patio_other.jpg" alt="First slide" width="300" height="300">
        <div class="carousel-caption d-none d-md-block">
            <h5>text 1</h5>
            <p>some more here</p>
        </div>
      </div>
      <div class="carousel-item" data-interval="10000">
        <img class="img-fluid" src="https://images.theconversation.com/files/350865/original/file-20200803-24-50u91u.jpg?ixlib=rb-1.1.0&rect=37%2C29%2C4955%2C3293&q=45&auto=format&w=926&fit=clip" alt="Second slide">
        <div class="carousel-caption d-none d-md-block">
            <h5>text 2</h5>
            <p>...</p>
        </div>
     </div>
      <div class="carousel-item" data-interval="10000">
        <img class="d-block w-75 mx-auto" src="https://www.aecmemphis.com/files/animal-emergency-center-cat-sleep.jpeg" alt="Third slide">
        <div class="carousel-caption d-none d-md-block">
            <h5>text 3</h5>
            <p>...</p>
        </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
  </div>
nik7
  • 806
  • 3
  • 12
  • 20
st123
  • 246
  • 3
  • 14

1 Answers1

0

The reason why when you click next and prev the page reloads is because you have an href in, change the href to [routerLink]="" and then it shouldn't reload anymore. Here's a link to passive routing: Passive Link in Angular 2 - <a href=""> equivalent. For angular 10 I think it is routerLink=""

Sad Frog
  • 114
  • 5