简体   繁体   English

AngularJS Google Maps API异步加载

[英]AngularJS Google Maps API Async loading

Hello I try to load the google maps api asynchronously in AngularJS following this link: http://angular-ui.github.io/angular-google-maps/#!/ 您好,我尝试通过此链接在AngularJS中异步加载google maps api: http : //angular-ui.github.io/angular-google-maps/#!/

I get the following error: 我收到以下错误:

Error: [$injector:modulerr] Failed to instantiate module due to:
[$injector:modulerr] Failed to instantiate module RegisterClientModule  due to:
undefined is not an object (evaluating 'uiGmapGoogleMapApiProvider.configure')

my code(Please note: I just started with AngularJS 2-3 days ago, I guess my mistake is easy to fix once I fully understand why this is not working): 我的代码(请注意:我是在2-3天前刚开始使用AngularJS,我想一旦我完全理解为什么它不起作用,我的错误就很容易解决):

var module = angular.module('RegisterClientModule', [])
.config(['$routeProvider', function    config($routeProvider,uiGmapGoogleMapApiProvider) {
$routeProvider.when('/registerclient', {
    controller: 'RegisterClientController',
    templateUrl: '/scripts/modules/RegisterClientModule/registerClientView.html'
});
uiGmapGoogleMapApiProvider.configure({
    v: '3.17',
    libraries: 'weather,geometry,visualization'
});
}]);

module.controller('RegisterClientController', ['$scope', function($scope, uiGmapGoogleMapApi ) {
uiGmapGoogleMapApi.then(function(maps) {
    console.log("Google maps api loaded");
});
$scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 };
console.log("Google maps api provider:"+uiGmapGoogleMapApi );

}]);

Thanks for your help 谢谢你的帮助

You missed to include uiGmapgoogle-maps in you app module. 您错过了在应用模块中包含uiGmapgoogle-maps That will make available the uiGmapGoogleMapApiProvider & all other API of Google map. 这将使uiGmapGoogleMapApiProvider和Google地图的所有其他API可用。

var module = angular.module('RegisterClientModule', ['uiGmapgoogle-maps'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM