Javascript $scope更改后的角度刷新
在我的应用程序中,我使用google maps API v3在地图上显示信息窗口。信息窗口中充满了Javascript $scope更改后的角度刷新,javascript,angularjs,google-maps,ionic-framework,Javascript,Angularjs,Google Maps,Ionic Framework,在我的应用程序中,我使用google maps API v3在地图上显示信息窗口。信息窗口中充满了$scope值。加载地图后,$scope会因事件而更改,但是“我的信息”窗口的内容仍然相同 我怎样才能使它刷新 我已经尝试在事件回调函数的末尾调用$scope.$apply(),但没有成功 Controller.js this.fillingMethod = function(){ info = MyService.getInformation();
$scope
值。加载地图后,$scope
会因事件而更改,但是“我的信息”窗口的内容仍然相同
我怎样才能使它刷新
我已经尝试在事件回调函数的末尾调用$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()" />
{{fillingInformation}}
看看这个。这是谷歌地图的角度。您将使用自定义指令。只需将$scope
放入其中,它就会自动更新,就像将scope放入html标记中一样
查看API,使用window
指令或windows
编辑:代码中有两个奇怪的东西
- 首先,为什么会有
ng non-bindable
,它会阻止angular在其中编译东西可能尝试删除它?
- 您正在使用的库看起来不像
angular ui
的angular google maps
。如果是的话。然后您将拥有自定义指令/attr。要更新,只需将信息放入标记中即可
{{填充信息[0]}
我已经在使用谷歌地图进行测角了。也许我没有正确地使用它,因为我的信息窗口在$scope update之后没有刷新。@Noémie O'connor到目前为止,我没有太多地使用它,但在通过API获取一些标记的测试中使用它时,它确实对我有用。这对我来说很好。让我看看你的代码。在那里发现了一些奇怪的东西。@Noémie O'connor更新答案,看看它是否适用于您:)