2015-05-07 556 views
0

你好我尝试异步加载谷歌地图API中AngularJS以下链接:http://angular-ui.github.io/angular-google-maps/#!/AngularJS谷歌地图API异步加载

我收到以下错误:

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') 

我的代码(请注意:我刚开始AngularJS 2-3天前,我想我的错误很容易解决,一旦我完全理解为什么这不工作):

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); 

}]); 

谢谢您帮助

回答

0

您错过了将uiGmapgoogle-maps包含在您的应用程序模块中。这将提供谷歌地图的所有其他API的uiGmapGoogleMapApiProvider &。

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

我已经添加了它,实际上,当我不尝试加载它的异步模块工作得很好,问题只发生在我尝试配置模块加载异步。 – user1990524

+0

有没有找到你的答案?遇到同样的问题,我添加了uiGmapgoogle-maps模块 –