Open In App

Angular PrimeNG Avatar Component

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. In this article, we will know how to use the Avatar component in Angular PrimeNG. Let’s learn about the properties, styling & their syntaxes that will be used in the code.

Avatar component: It is used to represent a person as an icon, image or label.



Properties of Avatar:

Properties for AvatarGroup:



 

Styling of Avatar:

Styling of AvatarGroup:

Creating Angular application & module installation:

Project Structure: It will look like the following:

Example 1: This is the basic example that shows how to use the avatar component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNg Avatar Component</h5>
<p-avatar label="A" styleClass="p-mr-1"></p-avatar>
<p-avatar
  label="B"
  styleClass="p-mr-1"
  size="large"
  [style]="{'background-color':'#3714e3', 'color': '#ffffff'}">
</p-avatar>
  
<p-avatar
  label="C"
  styleClass="p-mr-1"
  size="xlarge"
  [style]="{'background-color':'#1eff00', 'color': '#ff8400'}">
</p-avatar>




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

Output:

Example 2: In this example, we will be making circle-shaped avatars with icons.




<div class="card">
  <h5>Circle shaped avatar with icon</h5>
  <div>
    <p-avatar
      icon="pi pi-user"
      size="small"
      [style]="{'background-color': 'red', 'color': '#ffffff'}"
      shape="circle">
    </p-avatar>
  </div>
  <div>
    <p-avatar
      icon="pi pi-user"
      [style]="{'background-color': 'black', 'color': '#ffffff'}"
      shape="circle">
    </p-avatar>
  </div>
  <div>
    <p-avatar
      icon="pi pi-user"
      size="large"
      [style]="{'background-color':'green', 'color': '#ffffff'}"
      shape="circle">
    </p-avatar>
  </div>
  <div>
    <p-avatar icon="pi pi-user" size="xlarge" shape="circle"></p-avatar>
  </div>
</div>




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

Output:

Reference: https://primefaces.org/primeng/showcase/#/avatar


Article Tags :