I just create a filter to convert my date to time. And I would call in the official filter "date" of AngularJS.
project.date_created_at
and project.mel
don't have the same format. So I need to create a custom filter for project.date_created_at
.
HTML :
<span>{{ project.date_created_at | dateCustom }}</span>
<span>{{ project.mel | date:'dd/MM/yyyy' }}</span>
JS :
myApp.filter('dateCustom', function () {
return function (input) {
if(input != undefined) {
var d = new Date(input);
var time = d.getTime();
// use official $filter('date') here ?
}
}
});
I would like to use this format :
date:'dd/MM/yyyy'
You can inject $filter as a dependency like you would do it for a controller, a service or a directive.
myApp.filter('myFilter',[ '$filter', function ($filter) {
return function (input) {
/**
Do your stuff
**/
return $filter('date')(myDate,myFormat);
}
}]);
On a side note, you should use angular.isDefined instead of != undefined
.
See the documentation of $filter and of date for more details