Created
July 15, 2015 22:35
-
-
Save Jylanthas/28df1a583278fd19bcdc 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
<input class="form-control" type="text" unix-time-directive="timeFormat" ng-model="t.pickup_time"> | |
.directive('unixTimeDirective', function(moment) { | |
function link(scope, element, attrs, ngModelController) { | |
var format = scope.$eval(attrs.unixTimeDirective); | |
scope.$watch(attrs.unixTimeDirective, function(value) { | |
format = value; | |
}); | |
ngModelController.$parsers.push(function(data) { | |
return moment(data, format).unix(); | |
}); | |
ngModelController.$formatters.push(function(data) { | |
return moment.unix(data).format(format); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment