Angular 12/11 Bootstrap Carousel Tutorial Example

Angular 12/11 Bootstrap Carousel Tutorial Example

Angular 11/12 bootstrap carousel example. In this tutorial, you will learn step by step how to use bootstrap carousel in angular 11/12 app using ng-bootstrap/ng-bootstrap package.

And also, this tutorial will explain you on how to use bootstrap carousel in angular 11/12 app using ng-bootstrap/ng-bootstrap package.

How to Bootstrap Carousel In Angular 12/11?

  • Step 1 – Create New Angular App
  • Step 2 – Install bootstrap Carousel Library
  • Step 3 – Add Code on App.Module.ts File
  • Step 4 – Add Code on 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 for implement bootstrap carousel in angular 11 app. 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 – Add Code on App.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 – Add Code on View File

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

<div class="container-fluid">
  
<h1>Angular 11 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 Posts

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *