1
是否有什么特殊的我需要做的来访问$ timeout函数内的对象?
我得到的错误说的路线是不确定的,当我试图访问它在$超时功能,但$超时功能(其中控制台日志)之外它记录的对象,一切都在不出所料:
$scope.drawRoutes = function(routes) {
console.log(routes);
for (var i = 0; i < routes.length; i++) {
$timeout(function() {
MapService.directionsService.route(routes[i], function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
MapService.direction_renderers.push(new google.maps.DirectionsRenderer());
MapService.direction_renderers[MapService.direction_renderers.length - 1].setMap(MapService.gmaps.map);
MapService.direction_renderers[MapService.direction_renderers.length - 1].setDirections(response);
$scope.connectors_created += 1;
$scope.$digest();
}
});
}, 1000);
}
};
谢谢,做到了。我也意识到我的方法没有意义。我试图每隔1秒渲染一条新路由,但是我的方法等待1秒钟,然后渲染所有这些路由,因为所有超时都在毫秒之内调用:-( – andro1d
@ andro1d在这种情况下尝试更新 –
再次感谢,你是冠军!:-) – andro1d