简体   繁体   中英

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/#!/

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

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. That will make available the uiGmapGoogleMapApiProvider & all other API of Google map.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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