Open In App

Angular PrimeNG Tooltip Properties

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 see how to use the Tooltip properties along with code examples in Angular PrimeNG.

Tooltip component is used to make an element that provides advisory information for a component.



Angular PrimeNG Tooltip Properties:

Creating Angular application & module installation:



ng new appname
cd appname
npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

Project Structure

ng serve --open

Example 1: Below is the example that illustrates the use of Tooltip positions in Angular PrimeNG.




<div style="text-align : center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>PrimeNG Tooltip Properties</h5>
  <input type="text" 
         pInputText pTooltip="Course 1" 
         tooltipPosition="top" 
         placeholder="Geek 1" />
  <input type="text" 
         pInputText pTooltip="Course 2" 
         tooltipPosition="bottom" 
         placeholder="Geek 2" />
  <input type="text" 
         pInputText pTooltip="Course 3" 
         tooltipPosition="right" 
         placeholder="Geek 3" />
</div>




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




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

Output:

 

Example 2: This is the basic example that illustrates how to implement a focus event to display and blur to hide in the Tooltip component.




<div style="text-align : center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>PrimeNG Tooltip Properties</h5>
  
  <input type="text" 
         pInputText pTooltip="Course 1" 
         tooltipPosition="top" 
         placeholder="Geek 1" 
         tooltipEvent="focus" />
  
  <input type="text" 
         pInputText pTooltip="Course 2" 
         tooltipPosition="bottom" 
         placeholder="Geek 2"
         tooltipEvent="focus" />
  
  <input type="text" 
         pInputText pTooltip="Course 3" 
         tooltipPosition="right" 
         placeholder="Geek 3" 
         tooltipEvent="focus" />
</div>




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




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

Output:

 

Example 3: In this example, we are going to use the tooltip component in a button.




<div style="text-align : center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>PrimeNG Tooltip Properties</h5>
  <p-button pTooltip="Course 1" 
            tooltipPosition="top" 
            label="Geek 1" 
            class="p-mr-2">
  </p-button>
  <p-button pTooltip="Course 2" 
            tooltipPosition="bottom" 
            label="Geek 2" 
            class="p-mr-2">
  </p-button>
  <p-button pTooltip="Course 3" 
            tooltipPosition="right" 
            label="Geek 3" 
            class="p-mr-2">
  </p-button>
</div>




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




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

Output:

 

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


Article Tags :