Having an issue with updating a Date variable in JavaScript and TypeScript.
Here is the initial setup:
var stationdate = new Date(data.localTime);
JavaScript code for updating the variable every second:
window.setInterval(function () {
stationdate = new Date(stationdate.setSeconds(stationdate.getSeconds() + 1));
}, 1000);
TypeScript code to return the updated date to Angular UI:
window.setInterval(() => this.time = stationdate, 1000);
However, when trying to combine both functions, it stops working. See below:
window.setInterval(function () {
stationdate = new Date(stationdate.setSeconds(stationdate.getSeconds() + 1));
this.time = stationdate;
}, 1000);
Questioning if I am missing something with the fat arrow of TypeScript. What should be the proper function to achieve the desired result?