1
我正在使用NgMap,我需要在控制器中獲取路線。我試過以下內容:NgMap,如何訪問控制器中的指示?控制器中未定義map.directionsRenderer [0] .directions。
NgMap.getMap().then(function(map) {
console.log(map.directionsRenderers[0].directions);
});
但它返回undefined。我也嘗試使用$ scope.map,但也是未定義的。在我看來,{{map.directionsRenderers[0].directions.routes[0].legs[0].distance.text}}
按預期工作。
我的地圖如下:
<ng-map zoom="10" center="58.637381759037865,-3.0689620971679683">
<directions
draggable="false"
panel="directions-panel"
travel-mode="WALKING"
origin="58.637381759037865,-3.0689620971679683"
destination="50.063062230661494,-5.714178085327148"></directions>
<custom-marker id="start"
position="58.637381759037865,-3.0689620971679683">
<div> Start Here </div>
</custom-marker>
<custom-marker id="end"
position="50.063062230661494,-5.714178085327148">
<div> Ends Here </div>
</custom-marker>
</ng-map>
我缺少什麼簡單的事情?謝謝。
我添加了一個手錶的範圍變量如下'$範圍$腕錶('map.directionsRenderers [0]。方向',函數(){'並檢查它是否已被定義並且正在工作。這是最好的方法嗎? – JoshH2