有以下自定义Angular服务:
angular.module('app.services', ['uiGmapgoogle-maps']).factory('Geocoder', ['$q', ($q) ->
geocoder = new google.maps.Geocoder()
geocode: (location) ->
defer = $q.defer()
geocoder.geocode { location: location }, (results, status) ->
if status is google.maps.GeocoderStatus.OK
defer.resolve(results[0].formatted_address)
else
defer.reject()
defer.promise()
])
当我尝试在某个控制器中执行Geocoder.geocode(...)时,我收到错误"谷歌未定义",但如果我使用' google.maps.Geocoder&#39 ;在控制器中它运作良好。我的主要模块:
module = angular.module('app', ['app.controllers', 'app.directives',
'app.services', 'ui.bootstrap', 'ui.router', 'uiGmapgoogle-maps', 'dndLists'])
module.config(['$locationProvider', '$stateProvider', '$urlRouterProvider',
'$httpProvider', 'uiGmapGoogleMapApiProvider', ($locationProvider,
$stateProvider, $urlRouterProvider, $httpProvider,
uiGmapGoogleMapApiProvider) ->
uiGmapGoogleMapApiProvider.configure(
key: 'MYKEY'
libraries: 'places, geocoder'
v: '3.17')
$stateProvider.state('home'
url: ''
controller: 'HomeController'
templateUrl: 'templates/home.html'
)
$urlRouterProvider.otherwise ($injector) ->
$state = $injector.get('$state')
$state.go('home')
$locationProvider.html5Mode(true)
])
如您所见,我加载了Google地图。问题是什么?谢谢!