Ionic TypeError:无法读取未定义的属性“ router”

时间:2019-07-01 06:14:48

标签: typescript google-maps ionic-framework

当单击googlemaps信息窗口中的按钮时,我要浏览登录页面。但是在我的代码中,单击操作会给出如下错误:TypeError:无法读取未定义的属性“ router”

constructor(private router: Router) {}

标记代码

const marker = new google.maps.Marker({
  position: latlng,
  map: this.map,
  icon: icon
});

信息窗口

const contentString = '<h3>'+gorevliName+' ('+gorevliPoint+'/10)</h3>' +
'<p>Yetkinlik: '+gorevliAbility+'</p>' +
'<ion-button id = "request">Görevli Çağır!</ion-button>';

const infoWindow = new google.maps.InfoWindow({
  content: contentString,
  maxWidth: 400
});

创建标记和信息窗口,然后单击侦听器

marker.addListener('click', function() {
  infoWindow.open(this.map, marker);

  google.maps.event.addListenerOnce(infoWindow, 'domready', () => {
    document.getElementById('request').addEventListener('click', ()=> {
       this.router.navigate(['login']);//gives typeError
    });
  });
});

0 个答案:

没有答案