Open In App

Angular PrimeNG Image 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 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:

 



Syntax:

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

Creating Angular application & Module Installation:

ng new geeks_angular
cd geeks_angular
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.




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




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




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




: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.




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




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




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




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


Article Tags :