Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive('formatDate', function($filter) {
- return {
- restrict: 'A',
- require: 'ngModel',
- link: function(scope, element, attrs, modelCtrl) {
- // format text (model to view)
- modelCtrl.$formatters.push(function(value) {
- if(value !== "" && typeof value !== "undefined" && value !== null){
- return value.split("-").reverse().join("/");
- }
- });
- // format text (view to model)
- modelCtrl.$parsers.push(function(value) {
- if(value !== "" && typeof value !== "undefined" && value !== null){
- var date = new Date(value.split("/").reverse().join("-"));
- date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
- return date;
- }
- });
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement