Articles in this section
Category / Section

How to get started easily with Syncfusion Angular 8 Material TimePicker?

2 mins read

A quick start project that helps you to create an Angular 8 Material TimePicker component with a minimal code configuration.

Angular 8 Material TimePicker

The following section explains the steps required to create a simple Angular 8 Material TimePicker component.

Prerequisites

Make sure that you have the compatible versions of Angular in your machine before starting to work on this project.

Introduction

The Angular 8 Material TimePicker used in this project is created from the Syncfusion ej2-angular-calendars package. You can simply define it as <ejs-timepicker> within the template.

Dependencies

Before starting with this project, the Angular 8 Material TimePicker requires to add the Syncfusion ej2-angular-calendars package from npmjs, which are distributed in npm as @syncfusion scoped packages. TimePicker require following dependent packages for rendering the TimePicker component.

 

|-- @syncfusion/ej2-angular-calendars
    |-- @syncfusion/ej2-angular-base
    |-- @syncfusion/ej2-base
    |-- @syncfusion/ej2-calendars
        |-- @syncfusion/ej2-inputs
          |-- @syncfusion/ej2-splitbuttons
        |-- @syncfusion/ej2-lists
        |-- @syncfusion/ej2-popups
            |-- @syncfusion/ej2-buttons

 

The following CSS styles require dependencies to render the TimePicker component.

 

@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-calendars/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-calendars/styles/material.css';
 

 

Creating Angular Project

To create the Angular project using the Angular CLI tool, follow the given steps. Install Angular CLI 8 using following command.

 

npm install -g @angular/cli@8.1.1

 

Now, create a new Angular project by using the command ng new and navigate to that folder.

 

ng new <project name>
cd <project name>

 

Install the ej2-angular-calendars package using the npm install command.

 

npm install @syncfusion/ej2-angular-calendars --save

 

Adding Angular 8 Material TimePicker

 

You can add the Angular 8 TimePicker component by using ejs-timepicker directive and the attributes within the tag allows you to define other functionalities.

Import the TimePicker module into the Angular application (app.module.ts) from the ej2-angular-calendars package.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { TimePickerModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';
 
@NgModule({ 
    imports: [ BrowserModule, TimePickerModule ],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ]
})
 
export class AppModule {}

 

Define the Angular TimePicker code within the app.component.html file mapped against the templateUrl option in app.component.ts file. Here, the TimePicker component is rendered with the min and max properties.

[app.component.ts]

import {Component} from '@angular/core';
 
@Component ({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
 
export class AppComponent {
public month: number = new Date().getMonth();
  public fullYear: number = new Date().getFullYear();
  public date: number = new Date().getDate();
  public dateValue: Date = new Date(this.fullYear, this.month , this.date, 10, 0, 0);
  public minValue: Date = new Date(this.fullYear, this.month , this.date, 7, 0, 0);
  public maxValue: Date = new Date(this.fullYear, this.month, this.date, 16, 0 ,0);
  constructor () {}
}

[app.component.html]

<ejs-timepicker [value]='dateValue' [min]='minValue' [max]='maxValue'></ejs-timepicker>

 

Refer to the CDN link of CSS reference within the styles.css file.

@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-calendars/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-calendars/styles/material.css';

 

Run the application with the command ng serve and a TimePicker with material theme will be displayed on the browser as follows.

angular 8 timepicker


Conclusion

I hope you enjoyed learning about how to get started easily with Syncfusion Angular 8 Material TimePicker.

You can refer to our Angular TimePicker feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular TimePicker example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always 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