Articles in this section
Category / Section

How to get started easily with Syncfusion Angular 11 Color Picker?

2 mins read

A quick start project that helps you to create an Angular 11 Color Picker with a minimal code configurations.

The following section explains you how to create a simple angular 11 Color Picker component.

Prerequisites

 

Before start, we need following items to create Angular Color Picker in Angular 11 application

 

Dependencies

 

The angular 11 Color Picker is created from the Syncfusion ej2-angular-inputs package from npmjs, which are distributed in npm as @syncfusion scoped packages.

Creating Angular Project

 

  1. Install Angular CLI 11 using below command.

 

npm install -g @angular/cli@11.2.3

 

Note:

If you would like to follow and run the application in Angular 6 or Angular 5 or Angular 4, you need to replace the CLI command version number with the corresponding angular version number.

 

npm install -g @angular/cli@<CLI VERSION>

 

 

  1. Create a new Angular 11 project using angular cli and navigate to that folder.

 

ng new angular11-app

cd angular11-app

 

Adding Angular Color Picker

 

  1. After running the Angular 11 application successfully, configure the Angular Color Picker in this application. Install Angular Color Picker and EJ2 package using following command. 
    npm install @syncfusion/ej2-angular-inputs –save
    
    

 

The --save command will instruct the NPM to include a Color Picker package inside the dependencies section of the package.json.

  1. Import ColorPicker from installed package.
  2. Import and inject the other required modules within the providers section of app.module.ts.

 

import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { ColorPickerAllModule } from '@syncfusion/ej2-angular-inputs';

import { AppComponent } from './app.component';

import { FormsModule } from '@angular/forms';

import { enableRipple } from '@syncfusion/ej2-base';

 

enableRipple(true);

 

@NgModule({

  declarations: [

    AppComponent

  ],

  imports: [

    BrowserModule,

    FormsModule,

    ColorPickerAllModule

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule {}

 

  1. Add the given below angular color picker’s styles in styles.css.

 

@import "../node_modules/@syncfusion/ej2-base/styles/material.css";

@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";

@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";

@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";

@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";

 

  1. Add the angular Color Picker component in app.component.ts

 

import { Component } from '@angular/core';

 

@Component({

    selector: 'app-root',

    template: `<input ejs-colorpicker type='color' id='colorpicker'/>`

})

export class AppComponent {}

 

  1. Now serve the application using following command.

 

ng serve 

 

Once the files are compiled successfully, it will serve the site at localhost:4200

Screenshot:

ColorPicker_app

 

Inline Type

 

By default, the ColorPicker will be rendered using splitButton and open the pop-up to access the ColorPicker. To render the ColorPicker container alone and to access it directly, render it as inline. It can be achieved by setting the inline property to true.

The following sample shows the inline type rendering of ColorPicker.

[app.component.ts]

import { Component } from '@angular/core';

 

@Component({

    selector: 'app-root',

    template: `<input ejs-colorpicker type="color" id="colorpicker" [inline]= "true" [showButtons]= "false"/>`

})

export class AppComponent {}

 

Screenshot:

ColorPicker_inline

 

Summary

 

Refer to our documentation and online samples for more features. If you have any queries, please let us know in comments below.  You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied