我需要做一些特别的事情来访问 $timeout 函数中的对象吗?
当我尝试在 $timeout 函数中访问它时,我收到错误消息说路由未定义,但在 $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);
}
};