Open In App

Angular PrimeNG Image Indicator Templating

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 post, we will see Angular PrimeNG Image Indicator Templating.

The Image Component is used to show a single image to the user with the preview and basic transformations. In preview mode, when the image is hovered by the user, an eye icon is shown by default. This behavior can be altered by using the indicator template where we can define custom content.



Angular PrimeNG Image Indicator Templating Template:

 



Syntax:

<p-image 
    src="..."
    [preview]="..." 
    alt="...">

    <ng-template pTemplate="indicator">
        ...
    </ng-template>
</p-image>

Creating Angular application and Installing the Modules:

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

ng new myapp

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

cd myapp

Step 3: Install PrimeNG in your given directory.

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: This is the basic example of Image indicator templating. Here, the default eye icon has been replaced with the “pi-box” icon.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG Image Indicator Templating</h3>
  
<p-image 
    [preview]="true" 
    alt="logo">
  
    <ng-template pTemplate="indicator">
        <i 
            class="pi pi-box" 
            style="font-size: 24px;">
        </i>
    </ng-template>
</p-image>




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




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

Output:

 

Example 2: This is another example of indicator templating. Here we added an icon and a paragraph to the indicator template.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG Image Indicator Templating</h3>
  
<p-image 
    [preview]="true" 
    alt="logo">
  
    <ng-template pTemplate="indicator">
        <i class="pi pi-external-link mr-2"></i>
        <div><p>Preview Image</p></div>
    </ng-template>
</p-image>




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




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

Output:

 

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


Article Tags :