Skip to content

Instantly share code, notes, and snippets.

@gmann1982
Created April 13, 2016 06:30
Show Gist options
  • Save gmann1982/1069e09559242aaa6c332ddd7573029d to your computer and use it in GitHub Desktop.
Save gmann1982/1069e09559242aaa6c332ddd7573029d to your computer and use it in GitHub Desktop.
import { Component, OnInit, ElementRef, Input } from 'angular2/core';
import { NgControl, ControlValueAccessor } from 'angular2/common';
import "jquery";
import "jquery-ui";
declare var jQuery: any;
@Component({
selector: '.datepicker',
template: require('./datepicker.component.html'),
})
export class DatepickerComponent implements OnInit {
@Input() model;
el : ElementRef;
instance : any;
ngControl;
value: '';
constructor(el: ElementRef, ngControl: NgControl) {
this.el = el;
if (ngControl) {
this.ngControl = ngControl;
}
}
ngOnInit() {
this.instance = jQuery(this.el.nativeElement).datepicker({"dateFormat": "dd/mm/yy"});
this.instance.on('change', () => {
this.ngControl.viewToModelUpdate(this.instance[0].value);
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment