Open In App

Angular PrimeNG Avatar Label

Last Updated : 31 Aug, 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. This article will show us how to use the Avatar Label in Angular PrimeNG. Let’s learn about the properties and their syntaxes that will be used in the code.

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

Syntax:

<p-avatar 
    label="..." 
    styleClass="..." 
    size="large || xlarge" 
    [style]="{...}">
</p-avatar>

Angular PrimeNG Avatar Label properties:

  • label: It is used to define the text to display. It is of string data type, the default value is null.
  • size: It is used to set the size of the element, valid options are “large” and “xlarge”. It is of string data type, the default value is null.
  • style: It is used to set the inline style of the component. It is of object data type, the default value is null.
  • styleClass: It is used to define the style class of the component. It is of string data type, the default value is null.

Creating Angular application & module installation:

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

ng new appname

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

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: After complete installation, it will look like the following:

Project Structure

Run the below command to see the output:

ng serve --open

Example 1: Below is the example that illustrates the use of Angular PrimeNG Avatar Label using large labels.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Avatar Label</h5>
    <p-avatar 
        label="G" 
        styleClass="mr-2" 
        size="large"
        [style]="
        
            'background-color': 'green', 
             color: '#ffffff' 
         }">
    </p-avatar>
  
    <p-avatar
        label="E"
        styleClass="mr-2"
        size="large"
        [style]="
        
            'background-color': 'lightgreen', 
             color: '#000000' 
        }">
    </p-avatar>
  
    <p-avatar
        label="E"
        size="large"
        styleClass="mr-2"
        [style]="
        
            'background-color': 'yellow', 
             color: '#000000' 
        }">
    </p-avatar>
  
    <p-avatar
        label="K"
        size="large"
        styleClass="mr-2"
        [style]="
        
            'background-color': '#ccc450', 
             color: '#ffffff' 
        }">
    </p-avatar>
</div>


app.component.ts




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


app.module.ts




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


Output:

 

Example 2: Below is another example that illustrates Angular PrimeNG Avatar Label using xlarge labels.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Avatar Label</h5>
    <p-avatar 
        label="G" 
        styleClass="mr-3" 
        size="xlarge"
        [style]="
        
            'background-color': 'green', 
             color: '#ffffff' 
         }">
    </p-avatar>
  
    <p-avatar
        label="E"
        styleClass="mr-3"
        size="xlarge"
        [style]="
        
            'background-color': 'lightgreen', 
             color: '#000000' 
        }">
    </p-avatar>
  
    <p-avatar
        label="E"
        size="xlarge"
        styleClass="mr-3"
        [style]="
        
            'background-color': 'yellow', 
             color: '#000000' 
        }">
    </p-avatar>
  
    <p-avatar
        label="K"
        size="xlarge"
        [style]="
        
            'background-color': '#ccc450', 
             color: '#ffffff' 
        }">
    </p-avatar>
</div>


app.component.ts




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


app.module.ts




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


Output:

 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads