In my TypeScript file, I have the following function:
ngOnInit() {
if (sessionStorage['loyalPage']) {
this.page = Number(sessionStorage['loyalPage']);
}
this.webService.getLoyalPlayers(this.page).subscribe((player_vars:any)=> {
this.player_list= player_vars;
for (let i=0; i< this.player_list.length; i++) {
let clubJoined: Date = new Date(this.player_list[i].club_joined);
let todayDate: Date = new Date();
var clubJoinedYear = clubJoined.getUTCFullYear();
var currentYear = todayDate.getUTCFullYear();
var years_at_club = currentYear - clubJoinedYear;
}
})
}
player_list
: an array that contains players retrieved from MongoDBclubJoinedYear
: stores only the year when a player joined the current clubcurrentYear
: holds the current yearyears_at_club
: calculates how many years a player has been at the club
I want to display the integer variable years_at_club
in my HTML file and I am currently attempting it like this:
<div class="p-year">
{{ years_at_club }}
</div>
However, I encounter the following error:
Compiled with problems:
ERROR
src/app/loyal.component.html:71:24 - error TS2339: Property 'years_at_club' does not exist on type 'LoyalComponent'.
{{ years_at_club }}
~~~~~~~~~~~~~
src/app/loyal.component.ts:6:16
6 templateUrl: './loyal.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component LoyalComponent.
https://i.stack.imgur.com/lw8a8.jpg
How can I resolve this issue and successfully print this value in my HTML file?