Open In App

Angular MDBootstrap Carousel Component

MDBootstrap is a Material Design and bootstrap-based Angular UI library that is used to make attractive webpages with its seamless and easy-to-use component. In this article, we will know how to use Carousel Component in Angular MDBootstap. The Carousel Component is used to make a slideshow that uses CSS 3D transforms and a little JavaScript to cycle through a sequence of content, based on a collection of pictures.

Properties:



Syntax:

<mdb-carousel>
    <mdb-carousel-item>
      <img src="link" alt="First slide">
   </mdb-carousel-item>
</mdb-carousel>

Approach:



npm install
cd appname
ng serve

Project Structure: After complete installation, it will look like the following:

Project Structure

Example 1: This is the basic example that illustrates how to use the Carousel component in Angular MDBootstrap.




<div id='gfg'>
    <h2>GeeksforGeeks</h2>
    <h4>Angular MDBootstrap Carousel Component</h4>
    <br />
    <mdb-carousel [isControls]="false">
        <mdb-carousel-item
            <img class="w-25" src=
                 alt="First slide"
        </mdb-carousel-item>
        <mdb-carousel-item
            <img class="w-25" src=
                 alt="Second slide"
        </mdb-carousel-item>
        <mdb-carousel-item
            <img class="w-25" src=
                 alt="Third slide"
        </mdb-carousel-item>
    </mdb-carousel>
</div>




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}




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

Output:

Angular MDBootstrap Carousel Component

Example 2: This example illustrates the caption addition in a Carousel Component.




<div id="gfg">
    <mdb-carousel>
        <mdb-carousel-item>
            <div class="view w-100">
                <img style="height: 600px;" 
                     class="d-block w-100" 
                     src=
                     alt="First slide">
                <div class="mask rgba-black-light waves-light" mdbWavesEffect>
                </div>
            </div>
            <div class="carousel-caption">
                <h3 class="h3-responsive">
                    GeeksforGeeks
                </h3>
                <p>Red</p>
  
            </div>
        </mdb-carousel-item>
        <mdb-carousel-item>
            <div class="view w-100">
                <img style="height: 600px;" 
                     class="d-block w-100" 
                     src=
                     alt="Second slide">
                <div class="mask rgba-black-light waves-light" mdbWavesEffect>
                </div>
            </div>
            <div class="carousel-caption">
                <h3 class="h3-responsive">
                    GeeksforGeeks
                </h3>
                <p>Blue</p>
  
            </div>
        </mdb-carousel-item>
        <mdb-carousel-item>
            <div class="view w-100"
                <img style="height: 600px;" 
                     class="d-block w-100" 
                     src=
                     alt="Third slide">
                <div class="mask rgba-black-light waves-light" mdbWavesEffect>
                </div>
            </div>
            <div class="carousel-caption">
                <h3 class="h3-responsive">
                    GeeksforGeeks
                </h3>
                <p>Green</p>
  
            </div>
        </mdb-carousel-item>
    </mdb-carousel>
</div>




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{}




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

Output:

Adding a caption to the Carousel in Carousel Component

Reference: https://mdbootstrap.com/docs/angular/advanced/carousel


Article Tags :