Search results

Open the DatePicker popup upon focusing input of DatePicker in Angular DatePicker component

25 Oct 2021 / 1 minute to read

You can open the DatePicker popup on input focus by calling the show method in the input focus event.

The following example demonstrates how to open the DatePicker popup when the input is focused.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component, ViewChild } from '@angular/core';
import { CalendarComponent, FocusEventArgs } from '@syncfusion/ej2-angular-calendars';

@Component({
    selector: 'app-root',
    template: `<ejs-datepicker #default (focus)='onFocus($event)' placeholder='Choose a date'></ejs-datepicker>`
})
export class AppComponent {
    @ViewChild('default')
    public datepickerObj: CalendarComponent;

    onFocus(args: FocusEventArgs): void {
        this.datepickerObj.show();
    }
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { DatePickerModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


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

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);