在谷歌地图的infowindow内容中点击

gam*_*osa 12 google-maps angularjs

有没有办法在infowindow内容中创建ng-click angularjs指令?

var infowindow = new google.maps.InfoWindow({
                    map: map,
                    position: pos,
                    content: '<div ng-click="???" class="infowindow"></div>'
                  }); 
Run Code Online (Sandbox Code Playgroud)

keb*_*mix 21

您需要首先使用类似的东西编译HTML元素

var htmlElement = '<div ng-click="???" class="infowindow"></div>'
var compiled = $compile(htmlElement)($scope)
Run Code Online (Sandbox Code Playgroud)

然后将InfoWindow内容设置为类似的内容

var infowindow = new google.maps.InfoWindow({
                map: map,
                position: pos,
                content: compiled[0]
              }); 
Run Code Online (Sandbox Code Playgroud)

  • 您还必须确保您的html内容由单个根标记组成,否则由于我们使用的是索引[0],您只能看到第一个标记.如此简单的规则 - 例如,将所有内容都包含在div中. (3认同)
  • 我认为你不需要编译[0] .data的数据属性 (2认同)
  • @MajoB它实际上不适用于.data.应该编译[0],没有参数. (2认同)