Angular PrimeNG Form ColorPicker Formats 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 Formats Component.
The ColorPicker component is used to take color input from the user. It can give values in three formats. The format property is used to tell which format for choosing color is used. For example RGB, HSB, and hex.
Angular PrimeNG Form ColorPicker Formats Properties:
- format: It is used to tell the format which will be output by the color picker, The accepted values are “hsb”, “rgb”, and “hex”.
Syntax:
<p-colorPicker [(ngModel)]="..." format="..."> </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:
Example1: The below example illustrates how to use the RGB format of the ColorPicker component.
- app.component.html:
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" >w3wiki</ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 > Angular PrimeNG Form ColorPicker Formats Component </ h4 > < h5 >Formate: rgb</ h5 > < p-colorPicker [(ngModel)]="color2" format = "rgb" > </ p-colorPicker > </ div > |
- app.component.ts:
Javascript
import { Component } from "@angular/core" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" }) export class AppComponent { color2?: 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:
Example2: This is another code example showing the use of the HSb format of the color with the color picker component.
- app.component.html:
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" >w3wiki</ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 > Angular PrimeNG Form ColorPicker Formats Component </ h4 > < h5 >Formate: hsb</ h5 > < p-colorPicker [(ngModel)]="color2" format = "hsb" > </ p-colorPicker > </ div > |
- app.component.ts:
Javascript
import { Component } from "@angular/core" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" }) export class AppComponent { color2?: 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:
Reference: https://www.primefaces.org/primeng/colorpicker
Contact Us