ngMap https://github.com/allenhwkim/angularjs-google-maps에서 촬영이 구문 내부 NgMap에 대한 참조를 얻는 것은 잘 작동 :는 각도 컨트롤러
angular
.module('trails')
.controller('MyController', function (NgMap) {
NgMap.getMap().then(function (map) {
console.log(map.getCenter());
console.log('markers', map.markers);
console.log('shapes', map.shapes);
});
});
하지만 컨트롤러를 선언에 사용하는 구문은 다른 내가 오류 얻을 :
angular.js:13642 TypeError: Cannot read property 'getMap' of undefined
을 아래 라인에서 더 이상 실패합니다 :
NgMap.getMap().then(function (map) {
컨트롤러는 다음과 같이 선언됩니다 :
angular
.module('trails')
.controller('ActivityDetailsController', [
'$mdSidenav', '$mdBottomSheet', '$timeout', '$log', '$http', '$location', '$routeParams',
ActivityDetailsController
]);
function ActivityDetailsController($mdSidenav, $mdBottomSheet, $timeout, $log, $http, $location, $routeParams, NgMap) {
var self = this;
$http.get('/activity/detailStats/' + $routeParams.id, {
params: { max: "1000" }
})
.success(function (data) {
self.stats = data.stats;
// Zoom to fit
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < self.stats.activityTrackPoints.length; i++) {
var latlng = new google.maps.LatLng(self.stats.activityTrackPoints[i][0], self.stats.activityTrackPoints[i][1]);
bounds.extend(latlng);
}
NgMap.getMap().then(function (map) {
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
});
})
.error(function (data, status) {
console.error('https error', status, data);
})
.finally(function() {
});
내가 같은 다른 명백한 장소에서 NgMap를 추가하는 시도 :.
...'$routeParams', NgMap,
ActivityDetailsController...
또는 ActivityDetailsController을하고 $ 컨트롤러 선언 등 전 = NgMap을 주입하지만 위의 유사한 오류가 있습니다 NgMap을 참조 할 수 없다는 점에서
편집 : ngMap 종속성은 이미 답변과 비슷한 다른 파일에서 설정되었습니다. 미안하지만 이전에이 코드를 넣지 않았지만 작동하지 않는 위의 코드가 같은 위치에 있으므로 원본을 그대로 두는 것이 좋습니다.
var app = angular
.module('trails', ['ngMaterial', 'md.data.table', 'ngRoute', 'ngMap'])
나는 이것이 내가 잘못 NgMap가 NgMap이 컨트롤러 선언이나 뭔가를 사용하여 ... 또는 중 하나를 프레임 워크 대부분 내 경험 부족 주입하려고하는 방식으로하는 것입니다 있는지 확실하지 않습니다!
vm.map이나 필자의 경우 self.map에서 참조 할 필요가 없습니다. 오류는 여전히 "정의되지 않은 속성 'getMap'을 읽을 수 없습니다. 따라서 NgMap이 컨트롤러 함수를 선언하는 방식으로"주입 "하지 않는 것처럼 보입니다. – Steve
.controller ('ActivityDetailsController', [ '$ mdSidenav', '$ mdBottomSheet', '$ timeout', '$ log', '$ http', '$ location', '$ routeParams', 'NgMap', ActivityDetailsController ] – Abcd
Abcd에서 'NgMap'을 따옴표로 묶어야합니다 (항상 사용하지 않으려 고 노력했습니다). 왜 그런가? – Steve