谷歌地图infoWindow按钮(离子)问题

时间:2018-05-31 15:21:05

标签: javascript angular ionic-framework google-maps-markers

我想在离子

上做这样的事情

DEMO

但是当我添加一个infoWindows按钮时,我有一个问题, 特别是在本节(click)="ir()"(角度)



 ir(){
    console.log("go");
  }

      addMarker(position,map,title){
        var marker = new google.maps.Marker({
          position,
          map,
          title
        });

        var infoWindow = new google.maps.InfoWindow({
          content:" "
        });
        


        marker.addListener('click',function(){
          infoWindow.setContent('<h1> '+ title +'</h1>' +
              '<button class="mapaboton" (click)="ir()">Ver Detalles</button>'); 
            infoWindow.open(map,this);
        });



      }
&#13;
&#13;
&#13;

抱歉我的英文

当我点击它时没有任何反应。 然后我为(click)="ir()"更改了onclick="ir()"并且它向我发出了下一个错误

  

(index):1未捕获的ReferenceError:未定义ir       在HTMLButtonElement.onclick((index):1)

2 个答案:

答案 0 :(得分:1)

尝试

marker.addListener('click',()=>{
          infoWindow.setContent('<h1> '+ title +'</h1>' +
              '<button class="mapaboton" (click)="ir()">Ver Detalles</button>'); 
            infoWindow.open(map,this);
        });

答案 1 :(得分:1)

您可以为此使用NgZone:

import { NgZone } from '@angular/core';

constructor(public ngZone: NgZone) {}

(<any>window).ionicPageRef = {
    zone: this.ngZone,
    component: this
};

let infoWindow = new google.maps.InfoWindow({
    content: <button onClick='window.ionicPageRef.zone.run(function () { window.ionicPageRef.component.MyFunction() })'>My button</button>"
});

相关问题