我正在使用 angular-google-maps directive当我尝试删除绑定(bind)到 Controller 的标记时遇到问题。我尝试过各种版本的 Angular,并尝试过 angular-google-maps 的 master 和 r1-dev 分支。
我不知道为什么,但它似乎陷入了 $digest 函数,而当我过滤掉列表项时,这不会发生。抛出的异常是这样的:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
可以在这里看到一个演示,我的代码从 JavaScript 的第 550 行开始。上面几行是 angular-google-maps 指令。
最佳答案
这对我有用,这是通过阅读 angular-google-maps 模块问题队列中的其他一些相关错误得到的。
重点是您需要在 watch 内创建一个变量并使用它传递给模型参数。
基础 JS:
controller('MainCtrl', function ($scope, $filter) {
$scope.$watch("breweryFilter", function(breweryFilter){
$scope.filteredMarkers = $filter("filter")($scope.breweries, breweryFilter);
if (!$scope.filteredMarkers){
return;
}
});
});
过滤输入:
<input name="brewery-filter" class="form-control" type="search" ng-model="breweryFilter" placeholder="filter locations" />
包含标记指令的 map 指令:
<google-map
center="map.center"
zoom="map.zoom"
draggable="true"
control="map.control">
<window
show="breweryInfoWindow.showWindow"
coords="breweryInfoWindow.coords"
isIconVisibleOnClick="true"
options="breweryInfoWindow.options"
templateUrl="breweryInfoWindow.templateUrl"
templateParameter="breweryInfoWindow.templateParams"
data-ng-cloak>
_
</window>
<markers
models="filteredMarkers"
idKey="'nid'"
coords="'self'"
icon="'icon'"
doRebuildAll="true"
fit='true'
doCluster='true'
control="map.markersControl"
click="'onMarkerClicked'">
</markers>
</google-map>
希望对您有所帮助。
关于javascript - 使用angularjs过滤谷歌地图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412035/