Access the shared date format :
{{ dateValue | date:{{dateFormat}} }}
The service :
app.service('formatting', function() {
var format = new Object();
format.dateFormat = 'medium'
var getDateFormat = function(){
return format.dateFormat;
};
return {
getDateFormat : getDateFormat
};
});
But I don't think access the date format in this way is legal ?
How to centralize the the date format so can be used from multiple view pages ?
Update :
Here is fiddle I'm trying :
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())
}
})