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
Thanks my friend! You are welcome!