Time range in Angular Timepicker component

27 Sep 20232 minutes to read

TimePicker provides an option to select a time value within a specified range by using the min and max properties. The min value should always be lesser than the max value.

When the min and max properties are configured and the selected time value is out-of-range or invalid, then the model value will be set to out of range time value or null respectively with highlighted error class to indicates the time is out of range or invalid.

The value property depends on the min/max with respect to strictMode property.
The following example allows you to select a time value within a range of 9:00 AM to 11:30 AM.

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

//enable ripple style
enableRipple(true);

@Component({
    selector: 'app-root',
    template: `
        <ejs-timepicker [value]='dateValue' [min]='minDate' [max]='maxDate'></ejs-timepicker>
        `
})
export class AppComponent {
    public minDate: Date = new Date('8/3/2017 9:00 AM');
    public maxDate: Date = new Date('8/3/2017 11:30 AM');
    public dateValue: Date = new Date('8/3/2017 10:00 AM');
    constructor() {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { TimePickerModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        TimePickerModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

If the value of min or max property is changed through code behind you have to update the value property to set within the range.