Thursday, September 4, 2025
HomeLanguagesAngularAngular 14 Bootstrap 5 Carousel Example

Angular 14 Bootstrap 5 Carousel Example

Angular 14 bootstrap carousel example. In this tutorial, we will learn how to use bootstrap 5 carousel in the angular 14 apps using ng-bootstrap/ng-bootstrap package.

Angular 14 Bootstrap Carousel Example

Use the following steps to integrate bootstrap 5 carousel in angular 14 apps; as follows:

  • Step 1 – Create New Angular App
  • Step 2 – Install bootstrap Carousel Library
  • Step 3 – Import Modules in Module.ts File
  • Step 4 – Create Carousel in View File
  • Step 5 – Add Code On app.Component ts File
  • Step 6 – Start the Angular App

Step 1 – Create New Angular App

First of all, open your terminal and execute the following command on it to install angular app:

ng new my-new-app

Step 2 – Install bootstrap Carousel Library

Then install NPM package called ng-bootstrap/ng-bootstrap to implementing bootstrap carousel in angular apps. So, You can install the packages by executing the following commands on the terminal:

npm install jquery --save
ng add @ng-bootstrap/ng-bootstrap

Step 3 – Import Modules in Module.ts File

In this step, visit src/app directory and open app.module.ts file. And then add the following lines of into app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
  
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    NgbModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Step 4 – Create Carousel in View File

In this step, create a bootstrap carousel in the angular 14 apps. So, visit src/app/ and app.component.html and update the following code into it:

<div class="container-fluid">
  
<h1>Angular 14 Bootstrap Carousel Example - Tutsmake.com</h1>
  
<ngb-carousel>
  <ng-template ngbSlide *ngFor="let image of images">
    <div class="wrapper">
      <img [src]="image.src" alt="Random first slide">
    </div>
    <div class="carousel-caption">
      <h3>{{ image.title }}</h3>
      <p>{{ image.short }}</p>
    </div>
  </ng-template>
</ngb-carousel>
    
</div>

Step 5 – Add Code On app.Component ts File

In this step, visit the src/app directory and open app.component.ts. Then add the following code into component.ts file:

import { Component } from '@angular/core';
import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [NgbCarouselConfig]
})
export class AppComponent {
  title = 'ng-carousel-demo';
  
  images = [
    {title: 'First Slide', short: 'First Slide Short', src: "https://picsum.photos/id/700/900/500"},
    {title: 'Second Slide', short: 'Second Slide Short', src: "https://picsum.photos/id/1011/900/500"},
    {title: 'Third Slide', short: 'Third Slide Short', src: "https://picsum.photos/id/984/900/500"}
  ];
  
  constructor(config: NgbCarouselConfig) {
    config.interval = 2000;
    config.keyboard = true;
    config.pauseOnHover = true;
  }
}

Step 6 – Start the Angular App

In this step, execute the following command on terminal to start angular bootstrap carousel app:

ng serve

Recommended Angular Tutorials

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS