AngularJS 错误:[ng:areq] 参数'fn'不是函数,使用 Google Maps SDK 异步加载器获取字符串



错误:[$injector:module]未能实例化模块uiGmapgoogle映射,原因是:错误:[ng:areq]参数"fn"不是函数,得到字符串

我试着在main.js(app.js)文件中将谷歌地图api添加到我的angular js项目中,现在看起来是这样的。不幸的是,我收到了上面的错误。我真的很感谢一些指导,我花了3个小时试图解决这个问题,但我就是想不通。我正在尝试使用SDK异步加载程序而不是。

angular
.module('sfeVendorApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
['google-maps'.ns()]
])
  .config(['GoogleMapApiProvider'.ns()], function ($routeProvider, GoogleMapApi) {
GoogleMapApi.configure({
      key: 'AIzaSyCXxlIQE_baTY18opP79TFol5Ck40xQyP8',
      v: '3.17',
      libraries: 'weather,geometry,visualization'
  }); 
$routeProvider
  .when('/login', {
    templateUrl: 'views/login.html',
    controller: 'LoginCtrl'
  })
  .when('/openshop', {
    templateUrl: 'views/openshop.html',
    controller: 'OpenShopCtrl'
  })
  .when('/about', {
    templateUrl: 'views/about.html',
    controller: 'AboutCtrl'
  })
  .otherwise({
    redirectTo: '/login'
  });
})

我今天也遇到了同样的问题。我能够通过重新排列html中js引用的顺序来修复它。

我大致按以下顺序排列:

<script src="path/bluebird.js"></script>
<script src="path/jquery.min.js"></script>
<script src="path/angular.js"></script>
<script src="path/lodash.min.js"></script>
<script src="path/angular-google-maps.js"></script>

然后是我的控制器和服务。

我用这个文件作为参考https://github.com/angular-ui/angular-google-maps/blob/master/example/example.html

希望这能有所帮助。

最新更新