DOM not modified by var

why my DOM is not modified by this.tempo ?

{{ this.mensagemestimada }} {{ this.tempo }}
``` public temporizador(){ var counter = 0; var timer = setInterval(function() { if( counter >= 10 ) { clearInterval( timer ); }
this.tempo = counter;
console.log(this.tempo);
console.log( counter);
counter++;
}, 1000);

}

Remove this, use like {{ tempo }}. Just use ā€˜this.tempoā€™ to your .js file.

DOM not modifiedā€¦other solution ?

In any case, donā€™t use oldschool functions. You will loose scope of this.

public temporizador(){
    let counter = 0;
    let timer = setInterval( () => {
        if( counter >= 10 ) {
          clearInterval( timer );
        }

        this.tempo = counter;
        console.log(this.tempo);
        console.log( counter);
        counter++;
    }, 1000);
  }
2 Likes

Only because ā€œfunctionā€ ? WTF!

No, not wtf. Just basic es6 scoping with this :wink:

Thanks my friend! You are welcome!