내 앱이지도에 표시하기 위해 경로 (위도 및 경도 목록)를 가져와야합니다.좌표를 컨트롤러에 보내는 앵귤러 JS 서비스
모든 API 호출을 수행하는 기본 컨트롤러를 만들었습니다.
function mainController($scope, $http){
$http.get('/api/lastrun')
.success(function(data){
$scope.lastrun = data;
})
.error(function(data){
console.log('Error: ' + data);
});
}
lastrun에는 각 위치에 액세스 할 수있는 경로 배열이 있습니다.
나는function mapController($scope, positionService){
angular.extend($scope, {
run: {
lat: 0.0,
lng: 0.0,
zoom: 4
},
path: {
p1: {
color: 'red',
weight: 2,
latlngs: [
{ lat: 51.50, lng: -0.082 }, //here is an example of lat and lng in this controller
{ lat: 48.83, lng: 2.37 },
{ lat: 0, lng: 7.723812 }
]
}
}
});
}
각-지시 잎 내가 뭘 원하는 것은 아주 쉽게 보인다을 사용하여 mapController를 만들었습니다. latlngs 내 mapController에/api/lastrun을 호출하는 동안 얻을 수있는 위치 배열을 넣을뿐입니다.
저는 AngularJS의 서비스에 완전히 익숙하지 않지만 광산 (positionService)을 구축하려고했습니다. 그러나 그것은 작동하지 않았다.
여기에 누구라도 {lat :, lng :} 목록이 포함 된 배열을 내 서비스로 만들고이를 mapController에 호출하는 방법을 알고 있습니까? 다음
$scope.lastrun = [];
$http.get('/api/lastrun')
.success(function(data){
angular.forEach(data, function (value) {
$scope.lastrun.push({lat : value.lat, lng : value.lng});
});
}
})
과 :
HTTP 요청으로 작동하지 않을 것입니다. 작성해야 할 배열은 두 개의 다른 컨트롤러에 있습니다. – MaximeHeckel