Open In App

Angular PrimeNG Form ColorPicker Properties Component

Angular PrimeNG is a front-end UI component library for Angular Applications. It is developed and maintained by PrimeTek. PrimeNG helps developers to create stunning web interfaces in less time using pre-built components and themes. In this article, we will discuss the Angular PrimeNG Form ColorPicker Properties Component.

The Color Picker Component is used to take the input of color from the user. It provides a beautiful UI where users can choose the color and that color can be accessed by our application in different color formats.



Angular PrimeNG Form ColorPicker Properties:

 



Syntax:

<p-colorPicker 
    [(ngModel)]="..."
    format="hex | rgb | hsb"
    [hideTransitionOptions]="..."
    [showTransitionOptions]="...">
</p-colorPicker>

Creating Angular application and Installing the Modules:

Step 1: Create an Angular application using the following command.

ng new myapp

Step 2: After creating your project folder i.e. myapp, move to it using the following command.

cd myapp

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: After completing the above steps, the structure will look like the following.

Project Structure

Example 1: In this example, we used the inline property of the color picker to show it in inline mode rather than the default popup mode.




<h2 style="color: green">GeeksforGeeks</h2>
<h4>
      Angular PrimeNG Form ColorPicker <br>
    Properties Component
</h4>
  
<h3>Inline ColorPicker</h3>
<p-colorPicker 
    [inline]="true" 
    [(ngModel)]="selectedColor2">
</p-colorPicker>
  
<h3>Popup ColorPicker</h3>
<p-colorPicker 
    [(ngModel)]="selectedColor1">
</p-colorPicker>




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    styleUrls: ['./app.component.css'],
    templateUrl: './app.component.html',
    providers: [MessageService]
})
export class AppComponent {
    constructor(private messageService: MessageService) { }
    selectedColor1?: String;
    selectedColor2?: 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,
        ColorPickerModule,
        FormsModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule { }

Output:

 

Example 2: In this example, we used the showTransitionOptions and hideTransitionOptions properties to set the popup show and hide transitions to 1 second with linear progression.




<h2 style="color: green">GeeksforGeeks</h2>
<h4>
      Angular PrimeNG Form ColorPicker <br>
    Properties Component
</h4>
  
<p-colorPicker 
    [showTransitionOptions]="'1s linear'"
    [hideTransitionOptions]="'1s linear'"
    [(ngModel)]="selectedColor">
</p-colorPicker>




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    styleUrls: ['./app.component.css'],
    templateUrl: './app.component.html',
    providers: [MessageService]
})
export class AppComponent {
    constructor(private messageService: MessageService) { }
    selectedColor?: 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,
        ColorPickerModule,
        FormsModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule { }

Output:

 

Reference: http://primefaces.org/primeng/colorpicker


Article Tags :