Skip to content

Instantly share code, notes, and snippets.

@Lucasus
Last active December 27, 2015 18:09
Show Gist options
  • Save Lucasus/7367827 to your computer and use it in GitHub Desktop.
Save Lucasus/7367827 to your computer and use it in GitHub Desktop.
AngularJS directive for WinJS DatePicker control.
//Usage example: <div id="txtStartDate" data-win-datepicker="" data-ng-model="task.startDate">
module dt
{
"use strict";
export function WinDatePicker($parse): ng.IDirective
{
return {
restrict: 'A',
link(scope, element, attrs)
{
var modelAccessor = $parse(attrs.ngModel);
var datePicker = new WinJS.UI.DatePicker(element[0]);
scope.$watch(modelAccessor, function (val)
{
datePicker.current = val;
});
datePicker.addEventListener("change", function ()
{
var date = datePicker.current;
scope.$apply(function (scope)
{
modelAccessor.assign(scope, date);
});
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment