Having trouble getting help?
Contact Support
Contact Support
Custom event emitter in Angular Timepicker component
27 Apr 20242 minutes to read
The two-way binding in TimePicker can also be achieved using the custom event binding and property binding in the controls present in two different components. To create custom event, we need to create an instance of event emitter
.
In the following example, property binding is used to share the data from the parent component to the child component using @input directive and custom event binding is used to share the data from the child component to the parent component by using @output directive.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { TimePickerModule } from '@syncfusion/ej2-angular-calendars'
import { Component, ViewChild } from '@angular/core';
import { TimePickerComponent } from '@syncfusion/ej2-angular-calendars';
@Component({
imports: [ TimePickerModule ],
standalone: true,
selector: 'app-root',
template: `
<div class="parentelement">
<div class="datevalue">
<ejs-timepicker id="timepicker" #time (change)="deposit()" placeholder="Parent component" floatLabelType="Always" [value]="value" width="200px"></ejs-timepicker>
</div>
</div>
<child [xvalue]="value" (valueChange)="valuecheck($event)"> </child>
`,
})
export class ParentComponent {
@ViewChild('time')
public Time?: TimePickerComponent;
value: Date | any;
constructor() {
this.value = new Date("2/1/2020");
}
deposit() {
this.value = this.Time?.value;
}
valuecheck(args: any) {
this.value = args;
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));