Angular $scope 更改后刷新

Angular refresh after $scope change

在我的应用程序中,我使用 google 地图 API v3 以便在地图上显示信息 window。信息 windows 填充了 $scope 值。加载地图后,$scope因事件发生变化,但我的信息window的内容仍然相同。

如何让它刷新?

我已经尝试在我的事件回调函数结束时调用 $scope.$apply(),但没有成功。

Controller.js

this.fillingMethod = function(){
            info = MyService.getInformation();
            $scope.fillingInfo = info;
}
this.changeAnInfo = function(){
            var info = $scope.fillingInformation;
            var info = MyService.changeInfo(info);
            $scope.fillingInformation = info;
            $scope.$apply();
            }//Google InfoWindow is not refreshed.

View.html

    <!-- ng-controller is defined and refers to Controller -->
    <map id="map-canvas" center="current-location" zoom="15" ng-init="map.fillingMethod()">
        <marker id='test' position="current-location" animation="BOUNCE"></marker>
            <info-window id="marker-info" class="gmarker">
                <div ng-non-bindable="">
                     <div id="siteNotice"></div>
                         <h1 id="firstHeading" class="firstHeading">{{fillingInformation}}</h1>
                     </div>
                </div>
            </info-window>
    </map>
<button ng-click="changeAnInfo()" />

angular-google-maps 看看这个。它是 google 映射 angular。您将可以使用自定义指令。只需简单地将 $scope 放入其中,它就会自动更新,就像将作用域放入 html tags.

一样

查看 API,使用 window 指令或 windows

编辑:您的代码中有 2 个奇怪的地方

  • 首先,为什么有ng-non-bindable它会阻止angular编译里面的东西。 尝试删除它?
  • 您正在使用的库看起来不像 angular-google-mapsangular-ui。如果是的话。那么你将拥有自定义directive/attr。要更新,只需将信息放入标签即可。

<map id="map-canvas" center="current-location" zoom="15" ng-init="map.fillingMethod()">
    <marker id='test' position="current-location" animation="BOUNCE"></marker>
        <info-window id="marker-info" class="gmarker">
            <div >
                 <div id="siteNotice"></div>
                     <h1 id="firstHeading" class="firstHeading">{{fillingInformation[0]}}</h1>
                 </div>
            </div>
        </info-window>
</map>