AngularJS: Date filter problem
The date filter doesn't work on date strings that can be converted to Date objects via new Date()
HTML
<script src="http://code.angularjs.org/1.0.0rc1/angular-1.0.0rc1.js"></script>
<div ng:controller="Ctrl">
<h2>Date filter fails</h2>
<hr>
<ul>
<li ng:repeat="entry in entries">
{{entry.commit.author.date | date}}
</li>
</ul>
<hr>
<h2>Date filter works</h2>
<hr>
<ul>
<li ng:repeat="entry in entries">
{{entry.getDate() | date : dd-MM-yyyy}}
</li>
</ul>
</div>
JavaScript
function Ctrl($scope, Commit) {
$scope.entries = Commit.query();
}
var feed = angular.module('feed', [])
.factory('Commit', function($resource) {
var Commit = $resource('https://api.github.com/repos/msgilligan/angular.js/commits/:sha');
Commit.prototype.getDate = function() {
return new Date(this.commit.author.date);
}
return Commit;
});