Angular binding with a method is not working as expected

  angular, two-way-binding, typescript

I m trying to create a fake time stamp for my list elements. It should look like "4m ago, 1h ago, etc.."
So far i could manage it but when the time stamp is on the list, its not dynamic. I mean it stays always like "4m ago" but not changing after a minute later like "5m ago". I dont quite understand that because i m using new Date().getTime(), so i expect it ll always function from current time.
Any ideas what i do wrong ?
Thanks !

https://stackblitz.com/edit/angular-ph3dmv?embed=1&file=src/app/app.component.ts

 getFakeTimestamp(winner: SlotWidgetRecentWinnerObject) {
    const fakeTime = new Date().getTime() - 60 * winner.fakeTime;
       return this.slotWidgetService.timeSince(fakeTime);

  }



timeSince(timeStamp) {
    let now = new Date();
    let secondsPast = (now.getTime() - timeStamp) / 1000;

    if (secondsPast < 60) {
      return parseInt(String(secondsPast)) + 's';
    }
    if (secondsPast < 3600) {
      return parseInt(String(secondsPast / 60)) + 'm';
    }
    if (secondsPast <= 86400) {
      return parseInt(String(secondsPast / 3600)) + 'h';
    }
  }

And html

<div class="block__container--second">
                <div class="block__container--second--timestamp">{{getFakeTimestamp(winner)}} ago</div>
                <div class="block__container--second--winning">{{winner.amount}} €</div>
            </div>

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.