以下是json示例:
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.86755700000001,
"lng" : 151.201527
},
"viewport" : {
"northeast" : {
"lat" : -33.86752310000001,
"lng" : 151.2020721
},
"southwest" : {
"lat" : -33.8675683,
"lng" : 151.2013453
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "ce4ffe228ab7ad49bb050defe68b3d28cc879c4a",
"name" : "Sydney Showboats",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 750,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/107415973755376511005/photos\"\u003eSydney Showboats\u003c/a\u003e" …
Run Code Online (Sandbox Code Playgroud) 我试图在一些倒计时之后导航.这是我的代码
constructor(
private router: Router
) {}
onsubmit(){
//I call the count down function here
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);
}
Run Code Online (Sandbox Code Playgroud)
倒计时显示正常,但当它到达导航部分时,我收到此错误:
EXCEPTION: Cannot read property 'navigate' of undefined
Run Code Online (Sandbox Code Playgroud)
它做错了什么?