I got a view in angularjs and I\'m just trying to display the current date(formatted). I thought something like {{Date.now() | date:\'yyyy-MM-dd\'}}
Template
Directive
.directive('dateNow', ['$filter', function($filter) {
return {
link: function( $scope, $element, $attrs) {
$element.text($filter('date')(new Date(), $attrs.dateNow));
}
};
}])
Because you can't access the Date object direcly in a template (for an inline solution), I opteted for this Directive. It also keeps your Controllers clean and is reusable.