Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Angular PrimeNG Inplace Component

  • Last Updated : 24 Sep, 2021

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 Inplace component in Angular PrimeNG. We will also learn about the properties, events, methods & styling along with their syntaxes that will be used in the code. 

Inplace component: It is used to edit & display the content inplace of others at the same time & render the actual output while clicking the button to display.

Properties:

  • active: It is used to specify whether the content is displayed or not. It is of boolean datatype & the default value is false.
  • disabled: It specifies that the element should be disabled. It is of the boolean data type, the default value is false.
  • closable: It Displays a button to switch back to display mode. It is of the boolean data type, the default value is false.
  • preventClick: It specifies whether the component can be controlled full programmatic with activate() and deactivate() functions. It is of the boolean data type, the default value is false.
  • style: It sets an inline style of the component. It is of string data type, the default value is null.
  • styleClass: It is the style class of the component. It is of string data type, the default value is null.
  • closeIcon: It is the close icon, It is of string data type, the default value is pi pi-times.

Events:

  • onActivate: It is a callback that is fired when content is activated.
  • onDeactivate: It is a callback that is fired when content is deactivated

 



Methods:

  • activate: It is used to activates the content.
  • deactivate: It is used to deactivates the content.

Styling:

  • p-inplace: It is the Container element
  • p-inplace-display: It is the Display container
  • p-inplace-content: It is the Content container

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: It will look like the following:



Example 1: This is the basic example that illustrates how to implement the closable property in the Inplace Component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Inplace Component</h5>
<p-inplace closable="closable">
  <ng-template pTemplate="display"> Click to Edit </ng-template>
  <ng-template pTemplate="content">
    <input type="text" value="GeeksforGeeks" pInputText />
  </ng-template>
</p-inplace>

app.component.ts




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

app.module.ts




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

Output:

Example 2: In this example, we are making a button inside the Inplace Component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Inplace Component</h5>
<p-inplace>
  <ng-template pTemplate="display"
    Click Here 
  </ng-template>
  <ng-template pTemplate="content">
    <p-button>GfG</p-button>
  </ng-template>
</p-inplace>

app.component.ts




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

app.module.ts




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

Output:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!