【问题标题】:google maps infoWindow button ( ionic ) issue谷歌地图 infoWindow 按钮(离子)问题
【发布时间】:2018-11-10 16:04:06
【问题描述】:

我想在 ionic 上做这样的事情

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



      }

对不起我的英语

当我点击它时,什么也没有发生。 然后我将(click)="ir()" 更改为onclick="ir()",它会抛出下一个错误

(index):1 Uncaught ReferenceError: ir is not defined 在 HTMLButtonElement.onclick ((index):1)

【问题讨论】:

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


    【解决方案1】:

    试试

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

    【讨论】:

      【解决方案2】:

      您可以为此使用 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>"
      });

      【讨论】:

        猜你喜欢
        • 2011-11-16
        • 1970-01-01
        • 2018-05-24
        • 2016-09-23
        • 2019-07-15
        • 1970-01-01
        • 2011-09-14
        • 2012-09-21
        • 1970-01-01
        相关资源
        最近更新 更多