Reputation: 39034
I found the Angular Date documentation here, and thought the filter yyyy would be enough, but it's still attaching on the actual day.
My HTML:
<p class="footer_copy">© {{ footer.date | date : yyyy }} AT&T</p>
My Angular Directive for the footer, with a function to create a date:
// Directive for Footer
app.directive('appFooter', function () {
return {
restrict: 'E',
templateUrl: 'templates/app-footer.html',
controller: function(){
this.date = Date.now();
},
controllerAs:'footer'
};
});
However right now it spits out © Sep 24, 2014 AT&T
I'd like it to just create © 2014 AT&T
Upvotes: 1
Views: 1910
Reputation: 388376
You need to use to pass the format as a string
var app = angular.module('my-app', [], function() {})
app.directive('appFooter', function () {
return {
restrict: 'E',
template: '<p class="footer_copy">© {{ footer.date | date:"yyyy" }} AT&T</p>',
controller: function(){
this.date = Date.now();
},
controllerAs:'footer'
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="my-app">
<app-footer></app-footer>
</div>
var app = angular.module('my-app', [], function() {})
app.directive('appFooter', function() {
return {
restrict: 'E',
template: '<p class="footer_copy">© {{ footer.date | date:footer.dateFormat }} AT&T</p>',
controller: function() {
this.date = Date.now();
this.dateFormat = 'yyyy'
},
controllerAs: 'footer'
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="my-app">
<app-footer></app-footer>
</div>
Upvotes: 3