angularjs - ng-Map 未在信息窗口中显示文本

标签 angularjs google-maps ng-map

我有以下代码:

<ng-map>
        <marker ng-repeat="item in items" position="{{item[4]}},{{item[5]}}" name="{{item[1]}}" on-click="showInfoWindow('myInfoWindow')">
          <info-window id="myInfoWindow">
              <h4>{{this.name}}</h4>
          </info-window>
        </marker>
</ng-map> 

问题是我看到信息窗口,但 h4 内的文本为空,而不是 {{item[1]}} 的内容

最佳答案

info-window 指令不得与 ng-repeat 一起使用,以下示例演示如何为标记初始化信息窗口的单个实例:

angular.module('ngMap').controller('MyCtrl', function($scope,NgMap) {
  
  NgMap.getMap().then(function(map) {
    $scope.map = map;
  });
  $scope.cities = [
    {id: 1,name: 'Oslo', pos:[59.923043, 10.752839]},
    {id: 2,name: 'Stockholm',pos:[59.339025, 18.065818]},
    {id: 3,name: 'Copenhagen',pos:[55.675507, 12.574227]},
    {id: 4,name: 'Berlin',pos:[52.521248, 13.399038]},
    {id: 5,name: 'Paris',pos:[48.856127, 2.346525]}
  ];
  $scope.showCity = function(event, city) {
    $scope.selectedCity = city;
    $scope.map.showInfoWindow('myInfoWindow', this);
  };

});
<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>

<div ng-app="ngMap" ng-controller="MyCtrl">

  <ng-map default-style="true" zoom="5" center="59.339025, 18.065818">

    <info-window id="myInfoWindow" >
      <div ng-non-bindable>
        <h4>{{selectedCity.name}}</h4>
      </div> 
    </info-window>

    <marker ng-repeat="c in cities" 
      position="{{c.pos}}" title="{{c.name}}"  id="{{c.id}}"  on-click="showCity(event, c)">
    </marker>

  </ng-map>

</div>

JSFiddle

关于angularjs - ng-Map 未在信息窗口中显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33998014/

相关文章:

android - 在 Google map v2 中突出显示区域

google-maps - 使用 google geocode api 仅获取特定于国家/地区的结果

angularjs - 在angularjs中使用ngMap模块es6类时,使用 'this'时 'places-auto-complete'未绑定(bind)到构造函数

javascript - "Possibly unhandled rejection: ZERO_RESULTS" Angular 1.6.6 ng-map Geocode ui-bootstrap

javascript - ng-app 使脚本运行到无穷大

javascript - 单击一下即可切换两个不同的 div

angularjs - 谷歌地图 fitBounds 不工作

angularjs - 如何访问angular-ui-grid cellFilter中的整行数据

json - AngularJS、MVC4、Web API、Json 反序列化 $ref

javascript - 将事件监听器与 ngMap 结合使用