Open In App

Angular PrimeNG Form ColorPicker Styling Component

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. In this article, we will see the Angular PrimeNG Form ColorPicker Styling Component.

The ColorPicker Component is used to make a component in which users can select colors. The Styling Component helps to make the interactive Form ColorPicker by implementing the different stylings provided by Angular PrimeNG.

Angular PrimeNG Form ColorPicker Styling Component: These styling components are described below:

  • p-colorpicker: It is a styling container element.
  • p-colorpicker-overlay: It is a styling container element in overlay mode.
  • p-colorpicker-preview: It is a preview input in overlay mode.
  • p-colorpicker-panel: It is a styling panel element for the color picker.
  • p-colorpicker-content: It is a wrapper having color and hue sections.
  • p-colorpicker-color-selector: It is a color selector.
  • p-colorpicker-color: It is a styling color element.
  • p-colorpicker-color-handle: It is the handle for the color element.
  • p-colorpicker-hue: It is the Hue slider.
  • p-colorpicker-hue-handle: It is the handle of the hue slider.

 

Syntax:

<p-colorPicker [(ngModel)]="..." 
               [inline]="true">
</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: It will look like the following:

 

  • Steps to run the application: Run the below command to see the output
ng serve --save

Example 1: This example illustrates the Angular PrimeNG Form ColorPicker Styling.

  • app.component.html:

HTML




<div style="width: 80%;">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG Form ColorPicker Styling Component
    </h2>
    <p-colorPicker [(ngModel)]="selectColor" 
                   [inline]="true">
    </p-colorPicker>
</div>


  • app.component.css

CSS




:host ::ng-deep  .p-colorpicker-hue {
  background:red !important;
}


  • app.component.ts

Javascript




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


  • app.module.ts

Javascript




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:

 

Example 2: In this example, we will learn about another example of Angular PrimeNG Form ColorPicker Styling.

  • app.component.html:

HTML




<div style="width:80%">
    <h1 style="color:green">
          GeeksforGeeks
      </h1>
    <h2>
          Angular PrimeNG Form 
          ColorPicker Styling Component.
      </h2>
    <p-colorPicker [inline]="false" 
                   [(ngModel)]="gfg">  
    </p-colorPicker>
</div>


  • app.component.css

CSS




:host ::ng-deep .p-colorpicker {
    background: red !important;
}
  
:host ::ng-deep .p-colorpicker-overlay {
    background: red !important;
}
  
:host ::ng-deep .p-colorpicker-hue {
    background: white !important;
}


  • app.component.ts

Javascript




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
  
export class AppComponent {
    gfg: string = "#05f211";
}


  • app.module.ts

Javascript




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://primefaces.org/primeng/colorpicker



Last Updated : 22 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads