Open In App

Angular PrimeNG Image Styling

Last Updated : 08 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 Image Styling.

The Image component is used to add images to the angular page and also add some styles to it. Image Styling enables us to modify the default styles and customize them accordingly. 

Angular PrimeNG Image Styling:

  • p-image: It is the container element.
  • p-image-preview-container: It is the container element with preview enabled.
  • p-image-preview-indicator: It is the mask layer over the image when hovered.
  • p-image-preview-icon: It is the icon of the preview indicator.
  • p-image-mask: It is the preview overlay container.
  • p-image-toolbar: It is the transformation options container.
  • p-image-action: It is an element inside the toolbar.
  • p-image-preview: It is the image element inside the preview overlay.

 

Syntax:

<p-image src="Source" 
         alt="img">
</p-image>

Creating Angular application & Module Installation:

  • Create an Angular application using the following command.
ng new geeks_angular
  • After creating your project folder i.e. geeks_angular, move to it using the following command.
cd geeks_angular
  • Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following:

 

Example 1: In the following example, we have modified the preview icon color.

  • app.component.html

HTML




<h1 style="color: green; 
           text-align:center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Image Styling</h3>
<p-image [src]="images[1]" 
         alt="Image" 
         width="500px" 
         [preview]="true">
</p-image>


  • app.component.ts

Javascript




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
    providers: [MessageService],
})
export class AppComponent {
    images = [
    ];
    constructor(private messageService: MessageService) { }
    ngOnInit() { }
}


  • app.module.ts

Javascript




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 { }


  • app.component.css

CSS




:host ::ng-deep .p-image-preview-icon {
    color: black;
    background-color: greenyellow;
    scale: 3;
}


Output:

 

Example 2: In the following example, we have added a box shadow to the image container.

  • app.component.ts

HTML




<h1 style="color: green; 
           text-align:center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Image Styling</h3>
<p-image [src]="images[1]"
         alt="Image" 
         width="500px" 
         [preview]="true">
</p-image>


  • app.component.css

CSS




:host ::ng-deep .p-image-preview-container {
  box-shadow: 5px 5px 20px;
}


  • app.component.ts

Javascript




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
    providers: [MessageService],
})
export class AppComponent {
    images = [
    ];
    constructor(private messageService: MessageService) { }
    ngOnInit() { }
}


  • app.module.ts

Javascript




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: https://primefaces.org/primeng/image



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads