lundi 7 septembre 2020

glimmer.js time not updating

javascript

import Component from '@glimmer/component';
export default class TimerTrackerComponent extends Component {
    time = null;

    constructor(){
        super(...arguments);
        this.loadTime();
    }

    loadTime(){
        let timeNow = new Date();
        this.time = timeNow.toLocaleTimeString();
        setInterval(() => {this.loadTime();}, 1000);
    }
}

hbs

<div>
    <p></p>
</div>

I want to show a regular clock that updates every second but it only prints once or prints the same time over and over again. I tried adding an alert in the setInterval and it outputs the correct time every second.




Aucun commentaire:

Enregistrer un commentaire