为了账号安全,请及时绑定邮箱和手机立即绑定

谷歌地图 Angular9 打开信息窗口时出错,找不到 getAnchor()

谷歌地图 Angular9 打开信息窗口时出错,找不到 getAnchor()

繁星淼淼 2022-11-11 15:03:57
我正在使用这个谷歌地图角度组件教程,它工作得很好!但是打开信息窗口会引发异常。这是我的代码,它在 npm 包中的“MapInfoWindow”组件上调用“this.infoWindow.open”方法。import {  MapInfoWindow,  MapMarker,  GoogleMap} from '@angular/google-maps';export class YogabandEventsComponent implements OnInit {  @ViewChild(MapInfoWindow, {    static: false  }) infoWindow: MapInfoWindow;  @ViewChild(GoogleMap, {    static: false  }) googleMap: GoogleMap;  openInfo(marker: MapMarker, content) {    this.infoContent = content;    this.infoWindow.open(marker);  }}<google-map [options]="options" [zoom]="zoom" [center]="center" class="h-100" height="100%" width="100%">  <map-marker #markerElem *ngFor="let marker of markers" (mapClick)="openInfo(markerElem, marker.info)" [position]="marker.position" [label]="marker.label" [title]="marker.title" [options]="marker.options">  </map-marker>  <map-info-window>{{ infoContent }}</map-info-window></google-map>什么时候infoWindow.open(标记)被称为它进入google-maps.js // 第 1122 行但在第 1122 行收到错误,因为没有“getAnchor()”方法this.infoWindow.open(this._googleMap.googleMap, anchor ? anchor.getAnchor() : undefined);   // in google-maps.js open(anchor) {  this._assertInitialized();  this._elementRef.nativeElement.style.display = '';  this.infoWindow.open(this._googleMap.googleMap, anchor ? anchor.getAnchor() : undefined); // line 1122}
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

找到了答案。


查看了 Github 上的 repo 和一个示例。它与我上面发布的链接中的教程不同。


https://github.com/angular/components/tree/master/src/google-maps#readme


地图标记需要有这个道具


<map-marker 

  #somemarker="mapMarker" // not #markerElem like from the link

  (mapClick)="openInfoWindow(somemarker, marker.info)">

</map-marker>


查看完整回答
反对 回复 2022-11-11
  • 1 回答
  • 0 关注
  • 109 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号