Last active
October 16, 2015 18:53
-
-
Save zachlysobey/3cb0db7f5ebcad158f0a to your computer and use it in GitHub Desktop.
Hmmmmm
This file contains hidden or 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
angular.module('my.Module').directive('dateControl', dateControl); | |
function dateControl() { | |
return { | |
bindToController: true, | |
controller: Controller, | |
controllerAs: 'vm', | |
scope: { | |
isDataReady: '=', | |
dateMilliseconds: '=' | |
}, | |
template: '<input type="date" ng-model="vm.dateObj">' | |
}; | |
} | |
/* @ngInject */ | |
function Controller($scope, $log) { | |
const vm = this; | |
onDataReady(activate); | |
function onDataReady(callback) { | |
const unbind = $scope.$watch('vm.isDataReady', isDataReady => { | |
if (!isDataReady) { return; } | |
callback(); | |
unbind(); | |
}); | |
} | |
function activate() { | |
vm.dateObj = new Date(vm.dateMilliseconds); | |
syncDateMillisecondsWithProxy(); | |
} | |
function syncDateMillisecondsWithProxy() { | |
$scope.$watch('vm.dateObj', (newDate, oldDate) => { | |
if (newDate === oldDate) { return; } | |
vm.dateMilliseconds = newDate.getTime(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adam posted this, which is an interesting approach:
http://jsfiddle.net/asicfr/Mp7kT/
It essentially
requires
thengModel
controller, and usesngModel.$parsers
andngModel.$formatters
arrays.