Open In App

Angular PrimeNG Carousel Styling

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Carousel Styling.

The Carousel is a content slider component where an array of data is shown sequentially either manually or automatically. The Carousel in Angular PrimeNG provides great customization with different styling options that can be used to create dynamic carousels, along with enhancing the overall user experience.



Carousel Styling

Syntax:



<p-carousel [value]="...">
   ...
</p-carousel>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2:  After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

 

Example 1: This example describes the basic usage of the Carousel Styling with the help of the p-carousel in Angular PrimeNG.




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    title = 'GFG';
  
    images: any[] = [
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 1',
            title: 'Title 1'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 2',
            title: 'Title 2'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 3',
            title: 'Title 3'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 4',
            title: 'Title 4'
        },
  
    ];
}




<div id="GFG">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>Carousel Styling</h2>
  
    <div style="width:50%; ">
        <p-carousel [value]="images" 
                    [numVisible]="1" 
                    [numScroll]="1" 
                    [circular]="true">
            <ng-template let-item pTemplate="item">
                <img [src]="item.previewImageSrc" 
                     alt="item.alt"
                     width="500px">
            </ng-template>
        </p-carousel>
    </div>
</div>




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

Output:

 

Example 2: This is another example that describes the basic usage of the Carousel Styling with the help of the p-carousel-header and p-carousel-footer in Angular PrimeNG.




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    title = 'GFG';
    images: any[] = [
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 1',
            title: 'Title 1'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 2',
            title: 'Title 2'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 3',
            title: 'Title 3'
        },
        {
            previewImageSrc:
            thumbnailImageSrc:
            alt: 'Description for Image 4',
            title: 'Title 4'
        },
    ];
}




<div id="GFG">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>Carousel Styling</h2>
  
    <div style="width:50%; ">
        <p-carousel [value]="images" 
                    [numVisible]="1" 
                    [numScroll]="1" 
                    [circular]="true">
            <ng-template pTemplate="header">
                <h3 style="color:red">
                    I am a Header of Carousel
                </h3>
            </ng-template>
            <ng-template let-item pTemplate="item">
                <img [src]="item.previewImageSrc" 
                     alt="item.alt" 
                     width="500px">
            </ng-template>
            <ng-template pTemplate="footer">
                <h3 style="color:red">
                    I am a Footer of Carousel
                </h3>
            </ng-template>
        </p-carousel>
    </div>
</div>




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

Output:

 

Reference: http://primefaces.org/primeng/carousel


Article Tags :