我对 Angular 很陌生,我正在尝试使用它来集成谷歌地图:https ://github.com/allenhwkim/angularjs-google-maps
我遇到的问题是当我尝试使用 NgMap.getMap() 获取地图实例时,当我 console.log NgMap.getMap 我得到“找不到地图”。这就是我的代码的样子:
部分/home.html:
<h1>practice locater</h1>
<ng-map id="map" center="[40.74, -74.18]"></ng-map>
Javascript:
var app = angular.module('RIThym',['ngResource','ngRoute','ngMap']);
app.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'partials/home.html',
controller: 'HomeCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
app.controller('HomeCtrl',['$scope','$resource', 'NgMap',
function($scope, $resource, NgMap){
var Locations = $resource('/api/locations');
Locations.query(function(locations){
$scope.locations = locations;
});
var map = NgMap.getMap();
console.log(map);
NgMap.getMap().then(function(map){
console.log(map);
});
}]);