$ scope更改后的角度刷新

时间:2015-02-27 14:02:29

标签: javascript angularjs google-maps ionic

在我的应用中,我使用谷歌地图api v3,以便在地图上显示infowindow。 Infowindows充满了$ scope值。加载地图后,$ scope因事件而更改,但我的infowindow的内容仍然相同。

如何刷新?

我已经尝试在我的事件回调函数结束时调用$ 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()" />

1 个答案:

答案 0 :(得分:0)

angular-google-maps看看这个。这是谷歌地图的角度。您将拥有要使用的自定义指令。只需将$scope放入其中,它就会自动更新,就像您将范围放在html tags中一样。

查看API,使用window指令或windows

编辑:代码中有两件奇怪的东西

  • 首先,为什么ng-non-bindable会阻止角度来编译其中的内容。 尝试删除它吗?
  • 您使用的lib并不像angular-google-maps angular-ui <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>。如果是的话。然后你将有自定义指令/ attr。要更新,只需将信息放在标签内即可。

&#13;
&#13;
{{1}}
&#13;
&#13;
&#13;

相关问题