Skip to content

Instantly share code, notes, and snippets.

@ravipatel2293
Created September 26, 2017 06:44
Show Gist options
  • Save ravipatel2293/79b144532c074dd709ac086ac2cf2e07 to your computer and use it in GitHub Desktop.
Save ravipatel2293/79b144532c074dd709ac086ac2cf2e07 to your computer and use it in GitHub Desktop.
import { Input, Output, EventEmitter, ViewChild, ElementRef, Directive, Renderer } from ‘@angular/core’;
declare var jQuery: any;
@Directive({
selector: ‘[myDatepicker]’
})
export class DatePicker {
@Input() value = ‘’;
@Input() minimumDate: boolean = false;
@Input() onlyDatePicker: boolean = false;
@Output() dateChange = new EventEmitter();
constructor(public el: ElementRef, public renderer: Renderer) { }
ngOnInit() {
if (this.onlyDatePicker === true) {
jQuery(this.el.nativeElement).datepicker({
controlType: ‘select’
,oneLine: true,
minDate: this.minimumDate === false ? ‘’ : new Date(),
onSelect: (value) => {
this.value = value;
this.dateChange.next(value);
}
})
.datepicker(‘setDate’, this.value);
}
else {
jQuery(this.el.nativeElement).datetimepicker({
controlType: ‘select’,
oneLine: true,
timeFormat: ‘hh:mm tt’,
minDate: this.minimumDate === false ? ‘’ : new Date(),
onSelect: (value) => {
this.value = value;
this.dateChange.next(value);
}
})
.datepicker(‘setDate’, this.value);}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment