我在angularJS控制器中初始化Google地图,并向地图事件添加了侦听器
google.maps.event.addListener(map, 'dragend', MapMoveAround);
......
function MapMoveAround() {
console.log($location.url());
$location.path('/other_path');
console.log($location.url());
}
控制台显示,当我触发Google Map事件时,URL已更改,但我停留在旧页面上。如果我将$ location.path('/ other_path')更改为
window.location.replace('/#/other_path')
它将进入新页面,但“返回”按钮将不起作用。
谁能为此提供AngularJS解决方案?
通过事件运行角度代码将不会运行摘要循环,在这种情况下,您需要使用来手动运行它$scope.$apply()
以使$location
更改生效。
代码
google.maps.event.addListener(map, 'dragend', MapMoveAround);
......
function MapMoveAround() {
console.log($location.url());
$scope.$apply(function(){
$location.path('/other_path');
})
console.log($location.url());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句