diff --git a/src/ng-datepicker/ng-datepicker.component.ts b/src/ng-datepicker/ng-datepicker.component.ts
index 65b80c16e..84f2efda2 100644
--- a/src/ng-datepicker/ng-datepicker.component.ts
+++ b/src/ng-datepicker/ng-datepicker.component.ts
@@ -28,6 +28,7 @@ export interface DatepickerOptions {
barTitleFormat?: string; // default: 'MMMM YYYY'
firstCalendarDay?: number; // 0 = Sunday (default), 1 = Monday, ..
locale?: object;
+ readonly?: boolean;
minDate?: Date;
maxDate?: Date;
}
@@ -69,6 +70,7 @@ export class NgDatepickerComponent implements ControlValueAccessor, OnInit, OnCh
private positions = ['bottom-left', 'bottom-right', 'top-left', 'top-right'];
innerValue: Date;
+ readonly: boolean;
displayValue: string;
displayFormat: string;
date: Date;
@@ -148,6 +150,7 @@ export class NgDatepickerComponent implements ControlValueAccessor, OnInit, OnCh
this.barTitleFormat = this.options && this.options.barTitleFormat || 'MMMM YYYY';
this.firstCalendarDay = this.options && this.options.firstCalendarDay || 0;
this.locale = this.options && { locale: this.options.locale } || {};
+ this.readonly = this.options && this.options.readonly || false;
}
nextMonth(): void {
@@ -199,8 +202,8 @@ export class NgDatepickerComponent implements ControlValueAccessor, OnInit, OnCh
}
init(): void {
- const start = startOfMonth(this.date);
- const end = endOfMonth(this.date);
+ const start = startOfMonth(this.date || new Date(Date.now()));
+ const end = endOfMonth(this.date || new Date(Date.now()));
this.days = eachDay(start, end).map(date => {
return {
@@ -266,7 +269,7 @@ export class NgDatepickerComponent implements ControlValueAccessor, OnInit, OnCh
this.date = val;
this.innerValue = val;
this.init();
- this.displayValue = format(this.innerValue, this.displayFormat, this.locale);
+ this.displayValue = this.innerValue ? format(this.innerValue, this.displayFormat, this.locale) : '';
this.barTitle = format(startOfMonth(val), this.barTitleFormat, this.locale);
}
}