I am trying to make a carousel slide in angular. I took the html and css from ( https://getbootstrap.com/docs/4.0/examples/carousel/ ). But I didn't know how to use the javascript in the site. This html in app.component.html
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="first-slide" src="../assets/imgs/i1.jpg" alt="First slide">
<div class="container">
<div class="carousel-caption text-left">
<h1>Example headline.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p>
<a class="btn btn-lg btn-primary" href="#" role="button">Sign up today</a>
</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="second-slide" src="../assets/imgs/i2.jpg" alt="Second slide">
<div class="container">
<div class="carousel-caption">
<h1>Another example headline.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p>
<a class="btn btn-lg btn-primary" href="#" role="button">Learn more</a>
</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="third-slide" src="../assets/imgs/i3.jpg" alt="Third slide">
<div class="container">
<div class="carousel-caption text-right">
<h1>One more for good measure.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p>
<a class="btn btn-lg btn-primary" href="#" role="button">Browse gallery</a>
</p>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
The carousel isn't working, neither the next and previous buttons. Any help, i can't figure out why.
You did not add bootstrap to your project correctly.
Install Bootstrap 4 via npm:
npm install --save bootstrap
Add css to you main HTML file:
@import "~bootstrap/dist/css/bootstrap.css"
You also need to add jQuery, Popper.js and bootstrap.js
"scripts": [ "../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/popper.js",
"../node_modules/bootstrap/dist/js/bootstrap.js" ],
Also this may help you too : https://www.techiediaries.com/angular-bootstrap/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.