Retrieve the date in the shared format:
{{ dateValue | date:{{dateFormat}} }}
The following service is provided:
app.service('formatting', function() {
var format = new Object();
format.dateFormat = 'medium'
var getDateFormat = function(){
return format.dateFormat;
};
return {
getDateFormat : getDateFormat
};
});
Is accessing the date format in this manner permissible?
How can the date format be centralized for use across multiple view pages?
Check out this fiddle I've been working on:
fiddle src :
html :
<div ng-app="myApp">
<div ng-controller="farmController">
<div>{{ cTime | dateFormat }}
</div>
</div>
</div>
javascript :
var myApp = angular.module('myApp', []);
myApp.controller("farmController",function($scope){
$scope.cTime = 1439396762286;
})
myApp.service('formatting', function() {
var getDateFormat = function(){
return 'medium'
};
return {
getDateFormat : getDateFormat
};
});
myApp.filter('dateFormat', function($filter, formatting) {
return function(date) {
return $filter['date'](date, formatting.getDateFormat())
}
})