Open In App

Angular PrimeNG Galleria Indicator

Angular PrimeNG is an open-source UI component library for Angular Applications. Using the components provided by Angular PrimeNG, one can create stunning and responsive angular applications. In this article, we will see the Angular PrimeNG Galleria Indicator.

Galleria is an advanced component to display images in an attractive manner. It needs a template named item and an array of objects as the value. The use of the galleria component betters the user experience of the application. The Galleria Indicator allows users to navigate quickly through the galleria items.



Angular PrimeNG Galleria Indicator Properties:

 



Angular PrimeNG Galleria Indicator Templates:

Syntax:

<p-galleria [value]="img" 
            [showIndicators]="true" 
            indicatorsPosition="top">
       ...
</p-galleria>

Creating Angular application and Installing the Modules:

ng new myapp
cd myapp
npm install primeng --save
npm install primeicons --save

Project Structure: After completing the above steps, the structure will look like the following:

Project Structure

Example 1: In this example, we set the showIndicators property to true and by default, the indicators will show outside the content the current item of the galleria will change when we click on the indicators.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG Galleria Indicators</h3>
  
<h4>
    Indicators with Click Event
    and Outside the content
</h4>
  
<p-galleria [value]="img" 
            [containerStyle]="{'max-width': '500px'}" 
            [numVisible]="3" 
            [showIndicators]="true"
            [showThumbnails]="false">
       <ng-template pTemplate="item" let-img>
              <img [src]="img.URL" 
                   style="width: 100%; 
                          display: block;" />
       </ng-template>
</p-galleria>




import { Component } from '@angular/core';
  
interface GalleriaImage {
    URL: String;
}
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    img: GalleriaImage[] = [];
  
    ngOnInit() {
        this.img = [
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
        ];
    }
}




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

Output:

 

Example 2: In this example, the changeItemOnIndicatorHover property is set to true to change the galleria item when we hover over the indicators and the showIndicatorsOnItem property is also set to true to show the indicators on the top of the content.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG Galleria Indicators</h3>
  
<h4>
     Indicators with Hover Event
     and Inside the content
</h4>
  
<p-galleria [value]="img" 
            [containerStyle]="{'max-width': '500px'}" 
            [numVisible]="3"
            [changeItemOnIndicatorHover]="true"
            [showIndicatorsOnItem]="true" 
            [showIndicators]="true" 
            [showThumbnails]="false">
  
       <ng-template pTemplate="item" let-img>
              <img [src]="img.URL" 
                   style="width: 100%; 
                          display: block;" />
       </ng-template>
</p-galleria>




import { Component } from '@angular/core';
  
interface GalleriaImage {
    URL: String;
}
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    img: GalleriaImage[] = [];
  
    ngOnInit() {
        this.img = [
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
        ];
    }
}




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

Output:

 

Example 3: In this example, we set the indicatorsPosition property to the left to show the indicators on the left of the content and used the indicator template to show custom indicators.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG Galleria Indicators</h3>
  
<h4>
    Indicators with Hover Event
    and on the Left of the content
</h4>
  
<p-galleria [value]="img" 
            [containerStyle]="{'max-width': '500px'}" 
            [numVisible]="3" 
            [changeItemOnIndicatorHover]="true"
            [showIndicatorsOnItem]="true" 
            [showIndicators]="true" 
            indicatorsPosition="left" 
            [showThumbnails]="false">
  
       <ng-template pTemplate="item" let-img>
              <img [src]="img.URL"
                   style="width: 100%; 
                          display: block;" />
       </ng-template>
  
       <ng-template pTemplate="indicator" let-i>
              <div style="background: white; 
                          padding: 5px; 
                          border-radius: 10px">
                     <span style="color: green; 
                                  cursor: pointer">
                            {{i + 1}}
                     </span>
              </div>
       </ng-template>
</p-galleria>




import { Component } from '@angular/core';
  
interface GalleriaImage {
    URL: String;
}
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    img: GalleriaImage[] = [];
  
    ngOnInit() {
        this.img = [
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
            {
                URL:
            },
        ];
    }
}




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

Output:

 

Reference: https://primefaces.org/primeng/galleria/indicator


Article Tags :