How to get the current year in Angular template?

5/5 - (1 vote)

If you need to display the current year in Angular for copyright purposes, you can do it in the following way:

1. Create a footer component and add it to your app component.

  <app-footer></app-footer>

2. In the footer.component.ts get the current year:

  export class FooterComponent implements OnInit {
  currentYear: number = new Date().getFullYear();
  ...

3. Display the current year in the template:

<div id="footer">
  <p>
    {{currentYear}}
  </p>
</div>

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

Leave a Comment

WebPedia.net