I try to move after some countdown. Here is my code
constructor(
private router: Router
) {}
onsubmit(){
this.countdown();
}
countDown() {
var i = 5;
var myinterval = setInterval(function() {
document.getElementById("countdown").innerHTML = "redirecting in: " + i;
if (i === 0) {
clearInterval(myinterval );
this.router.navigate(['/About']);
}
else {
i--;
}
}, 1000);
}
The countdown indicator is displayed normally, but when it falls into the navigation part, I get this error:
EXCEPTION: Cannot read property 'navigate' of undefined
What am I doing wrong?
source
share