Open In App

Angular PrimeNG Avatar Templating

Last Updated : 17 Oct, 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. Avatars are used to denote letters, icons, and images in different shapes and background colors.

This article will show the Avatar Templating in Angular PrimeNG. Altering the normal behavior by using the avatar template where we can define custom content.

Approach: Let us create an Angular project and install PrimeNG UI module. Then we will create a UI that will showcase Angular PrimeNG Avatar Templating.

 

Creating React Project:

Step 1: To create an angular app, you need to install angular by command line interface through the npm command.

npm install -g angular-cli

Step 2: Now we will create a angular project.

ng new project_name

Step 3: After creating your react project, move into the folder to perform different operations.

cd project_name

Step 4: After creating the Angular application, Install the required module using the following command:

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

Project Structure: After running the commands mentioned in the above steps, if you open the project in an editor you can see a similar project structure as shown below. The new component user makes or the code changes, we will be performing will be done in the source folder.

 

Step to Run Application: Run the application using the following command from the root directory of the project:

ng serve --open

Example 1: We are creating a UI that shows Angular PrimeNG Avatar Templating.  Here, we are inserting a success tag inside the avatar.

  • app.component.html

HTML




<div style="margin:100px; text-align: center;">
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h3>
        Angular PrimeNG Avatar Templating
    </h3>
    <p-avatar size="xlarge" shape="circle">
        <p-tag value="GFG" 
               severity="success" 
               icon="pi pi-user" 
               [style]="{'margin':'20px'}">
        </p-tag>
    </p-avatar>
</div>


  • app.module.ts

Javascript




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


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: We are creating a UI that shows Angular PrimeNG Avatar Templating.  Here, we are inserting a progress spinner and skeleton component inside the avatar.

  • app.component.html

HTML




<div style="margin:100px; text-align: center;">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
      
    <h3>
        Angular PrimeNG Avatar Templating
    </h3>
      
    <p-avatar size="xlarge" shape="circle"
        [style]="{'background-color':'green',
        width:'100px',height:'100px',margin:'30px'}">
        <p-skeleton width="5rem" 
            height="5rem" shape="circle">
        </p-skeleton>
    </p-avatar>
    <p-avatar size="xlarge" [style]=
        "{'background-color':'green',
        width:'100px',height:'100px'}">
        <p-progressSpinner strokeWidth="2" 
            fill="#03fc24">
        </p-progressSpinner>
    </p-avatar>
</div>


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AvatarModule } from 'primeng/avatar';
import { SkeletonModule } from 'primeng/skeleton';
import { AppComponent } from './app.component';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        AvatarModule,
        ProgressSpinnerModule,
        SkeletonModule
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }


Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads