diff --git a/src/ng2-datetime/ng2-datetime.ts b/src/ng2-datetime/ng2-datetime.ts
index 2769dd9e..4000e08e 100644
--- a/src/ng2-datetime/ng2-datetime.ts
+++ b/src/ng2-datetime/ng2-datetime.ts
@@ -1,9 +1,9 @@
import {
- Component, Input, HostListener, AfterViewInit, OnDestroy,
- SimpleChanges, OnChanges, HostBinding, forwardRef
+ Component, Input, HostListener, AfterViewInit, OnInit, OnDestroy,
+ SimpleChanges, OnChanges, HostBinding, forwardRef, ViewChild, ElementRef
} from '@angular/core';
-import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
-import {ITimepickerEvent} from './ITimepickerEvent';
+import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
+import { ITimepickerEvent } from './ITimepickerEvent';
const CUSTOM_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
@@ -15,9 +15,9 @@ const CUSTOM_ACCESSOR = {
selector: 'datetime',
providers: [CUSTOM_ACCESSOR],
template: `
-
-
-
-
+
$('#' + this.idDatePicker)).datepicker(options);
+ let options = jQuery.extend({ enableOnReadonly: !this.readonly }, this.datepickerOptions);
+ this.datepicker = (
$(this.dateinput.nativeElement)).datepicker(options);
this.datepicker
.on('changeDate', (e: any) => {
let newDate: Date = e.date;
@@ -188,16 +205,14 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro
this.date = newDate;
this.onChange(newDate);
});
- } else if (this.datepickerOptions === false) {
- ($('#' + this.idDatePicker)).remove();
}
if (!this.timepicker && this.timepickerOptions !== false) {
- let options = jQuery.extend({defaultTime: false}, this.timepickerOptions);
- this.timepicker = ($('#' + this.idTimePicker)).timepicker(options);
+ let options = jQuery.extend({ defaultTime: false }, this.timepickerOptions);
+ this.timepicker = ($(this.timeinput.nativeElement)).timepicker(options);
this.timepicker
.on('changeTime.timepicker', (e: ITimepickerEvent) => {
- let {meridian, hours} = e.time;
+ let { meridian, hours } = e.time;
if (meridian) {
// has meridian -> convert 12 to 24h
@@ -207,7 +222,7 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro
if (meridian === 'AM' && hours === 12) {
hours = hours - 12;
}
- hours = parseInt(this.pad(hours), 10);
+ hours = parseInt(this.pad(hours));
}
if (!isDate(this.date)) {
@@ -220,8 +235,6 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro
this.date.setSeconds(e.time.seconds);
this.onChange(this.date);
});
- } else if (this.timepickerOptions === false) {
- ($('#' + this.idTimePicker)).parent().remove();
}
this.updateModel(this.date);