0

When click a button in googlemaps info window, i want to navigate login page. But in my codes click operation gives error like this: TypeError: Cannot read property 'router' of undefined

constructor(private router: Router) {}

Marker Codes

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

Info Window

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
});

Creating marker&InfoWindow and click listeners

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
    });
  });
});
OSentrk
  • 58
  • 1
  • 8
  • Do you need to call this function with the `this` scope? Please specify in which scope the function you want to call is defined. – Mathyn Jul 01 '19 at 06:18
  • 1
    you changed `this` here-> `marker.addListener('click', function() {` use arrow function – Suraj Rao Jul 01 '19 at 07:38

0 Answers0