Open In App

Angular PrimeNG Form ColorPicker Overlay and Inline Component

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 Angular PrimeNG Form ColorPicker Overlay and Inline Component.

The ColorPicker Component is used to take input of color from the user. In the inline color picker, the color selection box is shown to the user but in overlay mode, the color picker overlay appears when the user selects the colored div.



Angular PrimeNG Form ColorPicker Overlay and Inline Properties:

 



Syntax:

// Inline:
<p-colorPicker [(ngModel)]="..." 
    [inline]="true">
</p-colorPicker>

// Overlay:
<p-colorPicker [(ngModel)]="..."></p-colorPicker>

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: The project structure will look like the following.

Project Structure

Example1: In the below code, we will make use of the above syntax to demonstrate the use of the Form ColorPicker in Inline Mode.




<div style="text-align:center;">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</h3>
    <h4>Angular PrimeNG Form ColorPicker 
        Overlay and Inline Component</h4>
    <h5>Inline</h5>
    <p-colorPicker 
        [(ngModel)]="color2" 
        [inline]="true">
    </p-colorPicker>
</div>




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




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 { ColorPickerModule } from "primeng/colorpicker";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FormsModule,
        ColorPickerModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Output:

 

Example2: In the below code, we will make use of the above syntax to demonstrate the use of the Form in Overlay Mode.




<div style="text-align:center;">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</h3>
    <h4>Angular PrimeNG Form ColorPicker 
        Overlay and Inline Component</h4>
    <h5>Overlay</h5>
    <p-colorPicker 
        [(ngModel)]="color2">
    </p-colorPicker>
</div>




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




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 { ColorPickerModule } from "primeng/colorpicker";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FormsModule,
        ColorPickerModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

Output:

 

Reference: https://www.primefaces.org/primeng/colorpicker


Article Tags :