Skip to content

options attribute

kekeh edited this page May 26, 2019 · 4 revisions
<input angular-mydatepicker [(ngModel)]="model" [options]="myDatePickerOptions" 
    #dp="angular-mydatepicker">
import {IAngularMyDpOptions} from 'angular-mydatepicker';

export class MyApp {
    myDatePickerOptions: IAngularMyDpOptions = {
        dateFormat: 'dd.mm.yyyy',
        dateRange: true
        // other options here
    }

    constructor() {}

    // change value of the option dynamically
    changeDateFormatDynamically(): void {
        let copyOfOptions: IAngularMyDpOptions = this.getCopyOfOptions();
        copyOfOptions.dateFormat = 'yyyy-mm-dd';
        this.myDatePickerOptions = copyOfOptions;
    }

    // change value of the option dynamically
    changeDatePickerModeDynamically(): void {
        let copyOfOptions: IAngularMyDpOptions = this.getCopyOfOptions();
        copyOfOptions.dateRange = false;
        this.myDatePickerOptions = copyOfOptions;
    }

    getCopyOfOptions(): IAngularMyDpOptions {
        return JSON.parse(JSON.stringify(this.myDatePickerOptions));
    }
}