2

我正在尝试使用以下代码让 angularjs-google-maps 在 angularjs 项目中显示地图。(仅显示相关的代码部分。)

在 index.html 中:

<script src="http://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.min.js"></script>

在 app.js 中:

var forecastApp = angular.module('forecastApp', ['ngRoute', 'ngResource', 'ngSanitize','angularjs-dropdown-multiselect','ngMap']);

...

.when('/map',
                {
                    controller:'mapController',
                    templateUrl:'app/map/_map.html'
                })

在 _map.html 中:

<div map-lazy-load="http://maps.google.com/maps/api/js">
  <map center="current-location" zoom="8">
    <info-window position="current-location" visible="true">
      <span>Loation found using HTML5.</span>
    </info-window>
  </map>
</div>

mapController.js 中的 mapController 已实例化且为空。

在 Firefox 中,我得到一些无限循环,数百个导航栏相互叠加,直到崩溃,在 Chrome 中,我得到超时而没有显示任何内容(只是等待 rawgit.com)并设法获得“超出堆栈大小”错误一次,可能表示循环引用?谷歌地图的延迟实例化不是问题,“等待...”显示了为下载 js/css 代码访问的最后一个域,因此服务器没有关闭(尝试包括本地存储的 ng-map.min.js也)。

谢谢你。

4

1 回答 1

1

很抱歉将我的问题归咎于 angularjs-google-maps 模块。这是angularjs中的路由。app.js 中的以下代码部分导致了问题:

forecastApp.config(function($routeProvider) {
    $routeProvider
        .when('/',
            {
                controller:'',
                templateUrl:''
            })
        .when('/location',
            {
                controller:'locationController',
                templateUrl:'app/location/_location.html'
            })
        .otherwise({redirectTo:'/'});
});

when('/')没有控制器和模板otherwise({redirectTo:'/'})并使角度进入一些奇怪的循环。删除该when('/')部分或向其添加控制器和模板后,一切正常。

于 2015-06-11T18:11:22.047 回答