Search results

Two-way binding

The following example demonstrates how to achieve two-way binding by binding the value to the first DateRangePicker component by using property binding and binding the model data using ngModel to the second DateRangePicker component. The value of the DateRangePicker will get change, when their is any change in the property value or model value.

The two-way binding can also be achieved only by using property binding or model binding in the DateRangePicker component.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewChild } from '@angular/core';
import { DateRangePickerComponent } from '@syncfusion/ej2-angular-calendars';

@Component({
    selector: 'app-root',
    template: `
        <!-- two-way binding using the value binding and model binding in the DateRangePicker --->
        <ejs-daterangepicker #ejDateRangePicker [(value)]='value'  width="230px"></ejs-daterangepicker>
        <ejs-daterangepicker #ejDateRangePickers [(ngModel)]='value'  width="230px"></ejs-daterangepicker>
        `
})
export class AppComponent {
    value: Date;
    constructor() {
        this.value = [new Date('1/1/2020'), new Date('2/1/2023')];
    }
}
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { DateRangePickerModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


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

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  top: 45%;
  left: 45%;
}

#element {
    display: block;
    height: 350px;
}

#wrapper {
    width: 550px;
    margin: 0 auto;
}

#fisrtdaterange, #seconddaterange {
    margin-right:30px;
}