Open datepicker popup on input click in Angular Datepicker component
18 Nov 20181 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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DatePickerModule } from '@syncfusion/ej2-angular-calendars'
import { Component, ViewChild } from '@angular/core';
import { CalendarComponent, FocusEventArgs } from '@syncfusion/ej2-angular-calendars';
@Component({
imports: [
DatePickerModule
],
standalone: true,
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 as any).show();
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));