Open In App

Angular PrimeNG Inplace Data

Angular PrimeNG is a UI component library for Angular Applications. It offers many pre-built themes and UI components for a variety of tasks like inputs, menus, charts, Buttons, etc. In this article, we will be seeing Angular PrimeNG Inplace Data.

The Inplace component is used to provide an easy to do editing and display to the user. When the output of the Inplace component is clicked the content is revealed. The Inplace can also be used to show data using tables and other data components as content.



Angular PrimeNG Inplace Data Properties: There are no properties for the Angular PrimeNG Inplace Data.

 



Syntax:

<p-inplace>
    <ng-template pTemplate="display">
        ...
    </ng-template>
    <ng-template pTemplate="content">
        <p-table [value]="...">
            <ng-template pTemplate="header">
                ...
            </ng-template>
            <ng-template let-person pTemplate="body">
                ...
            </ng-template>
        </p-table>
    </ng-template>
</p-inplace>

Creating Angular Application and Installing the Module:

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: Finally, Install PrimeNG in your given directory.

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

Project Structure: The project Structure will look like this after following the above steps:

Project Structure

Example 1: In this example, we used the table component to show data as the content of the Inplace.

app.component.html:




<h2 style="color: green;">GeeksforGeeks</h2>
<h3>Angular PrimeNG Inplace Data</h3>
  
<p-inplace>
    <ng-template pTemplate="display">
        Reveal the Data
    </ng-template>
    <ng-template pTemplate="content">
        <p-table [value]="people">
            <ng-template pTemplate="header">
                <tr>
                    <th>Name</th>
                    <th>Profession</th>
                    <th>Age</th>
                </tr>
            </ng-template>
            <ng-template let-person pTemplate="body">
                <tr>
                    <td>{{person.name}}</td>
                    <td>{{person.profession}}</td>
                    <td>{{person.age}}</td>
                </tr>
            </ng-template>
        </p-table>
    </ng-template>
</p-inplace>

app.component.ts:




import { Component } from "@angular/core";
  
interface Person {
    name: String;
    profession: String;
    age: Number;
}
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    people: Person[] = [];
    ngOnInit() {
        this.people = [
            {
                name: "Krish",
                profession: "Doctor",
                age: 32
            },
            {
                name: "Raman",
                profession: "Engineer",
                age: 26
            },
            {
                name: "Shubh",
                profession: "Teacher",
                age: 41
            },
            {
                name: "Divya",
                profession: "Manager",
                age: 27
            },
            {
                name: "Jayesh",
                profession: "Mechanic",
                age: 33
            }
        ];
    }
}

app.module.ts:




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

Output:

 

Example 2: In this example, we used the tree component as the content of the inplace to show data to the user.

app.component.html:




<h2 style="color: green;">GeeksforGeeks</h2>
<h3>Angular PrimeNG Inplace Data</h3>
  
<p-inplace>
    <ng-template pTemplate="display">
        Reveal the Tree
    </ng-template>
    <ng-template pTemplate="content">
        <p-tree [value]="treeData"></p-tree>
    </ng-template>
</p-inplace>

app.component.ts:




import { Component } from "@angular/core";
import { TreeNode } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    treeData: TreeNode[] = [];
  
    ngOnInit() {
        this.treeData = [{
                label: "India",
                children: [
                    {
                        label: "Delhi"
                    },
                    {
                        label: "Amritsar"
                    },
                    {
                        label: "Noida"
                    }
                ]
            },
            {
                label: "United Kingdom",
                children: [
                    {
                        label: "London"
                    },
                    {
                        label: "Manchester"
                    }
                ]
            },
            {
                label: "Dubai",
            }
        ];
    }
}

app.module.ts:




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule }
    from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { TableModule } from "primeng/table";
import { TreeModule } from "primeng/tree";
import { InplaceModule } from "primeng/inplace";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        InplaceModule,
        FormsModule,
        TableModule,
        TreeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule { }

Output:

 

Reference: http://primefaces.org/primeng/inplace


Article Tags :