Created
September 26, 2017 06:44
-
-
Save ravipatel2293/79b144532c074dd709ac086ac2cf2e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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