Last active
December 27, 2015 18:09
-
-
Save Lucasus/7367827 to your computer and use it in GitHub Desktop.
AngularJS directive for WinJS DatePicker control.
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
//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