【问题标题】:.ns() undefined in google angular maps directive.ns() 在谷歌角度地图指令中未定义
【发布时间】:2014-10-17 12:46:29
【问题描述】:

我正在尝试在我的应用中使用 angular google maps 指令,但我不断收到“未定义错误”

这是我的 app.js

angular.module('app', ['cs'])

.config(['GoogleMapApiProvider'.ns(), function (GoogleMapApi) {
        GoogleMapApi.configure({
            //    key: 'your api key',
        v: '3.17',
        libraries: 'weather,geometry,visualization'
    });
}])

.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
    //routes
}])

和我的控制器

angular.module('cs.Controllers')
.controller('MapController', ['$rootScope', '$scope', '$window', '$document', 'MenuService', 'GoogleMapApi'.ns(),
    function($rootScope, $scope, $window, $document, menuService, GoogleMapApi) {

    $rootScope.menuList = menuService.all();


}]);

可能是什么问题

【问题讨论】:

  • 'GoogleMapApiProvider' 是一个字符串。 'GoogleMapApiProvider'.ns() 调用字符串的ns 方法。我从未听说过内置的ns 方法,所以我猜您正在使用的某个库应该添加该方法(AngularJS 不会添加它),对吧?这对我来说毫无意义,但你是编写代码的人。
  • @SergiuParaschiv 代码来自网站上的文档angular-ui.github.io/angular-google-maps/#!/api
  • 你为什么要用两个.config()

标签: javascript angularjs google-maps-api-3


【解决方案1】:

对于其他添加了缺少的依赖声明的人,请参阅:angular-google-maps , undefined is not a function

看起来他们已经摆脱了 ns() 函数,但还没有更新文档:

https://github.com/angular-ui/angular-google-maps/pull/872/ https://github.com/angular-ui/angular-google-maps/issues/821

在你的代码中更新'string'.ns() 的所有实例为'uiGmapstring',你应该会很好。

【讨论】:

    【解决方案2】:

    您的应用中缺少依赖项声明。

      angular.module('app', ['google-maps'.ns(),'cs.Controllers']
    

    这是一个使用项目演示页面之一的 plunker。我将其更改为使用新的提供程序。 http://plnkr.co/edit/eUbkv2qKu92T9iUp7yAF?p=preview

    【讨论】:

      猜你喜欢
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 2020-09-20
      • 2016-07-25
      • 2017-10-09
      • 2015-06-17
      相关资源
      最近更新 更多