我正在尝试使用以下代码让angularjs -google- map在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已实例化且为空。
在火狐中,我得到了一些无限循环,数百个导航栏堆叠在一起,直到崩溃,在Chrome中,我得到超时,没有任何显示(只是等待rawgit.com),并设法得到一个“堆栈大小超过”错误一次,表明可能是循环引用?google地图的懒惰实例化不是问题,“等待...”显示最近访问的用于下载js/css代码的域,因此服务器没有停机(也尝试包含本地存储的ng-map.min.js )。
谢谢。
发布于 2015-06-12 02:11:22
很抱歉将我的问题归咎于angularjs-google-map模块。这是angularjs中的路由。app.js中的以下代码部分导致了问题:
forecastApp.config(function($routeProvider) {
$routeProvider
.when('/',
{
controller:'',
templateUrl:''
})
.when('/location',
{
controller:'locationController',
templateUrl:'app/location/_location.html'
})
.otherwise({redirectTo:'/'});
});没有控制器、模板和otherwise({redirectTo:'/'})的when('/')让angular陷入了某种奇怪的循环。删除when('/')部分或向其中添加控制器和模板后,一切正常。
https://stackoverflow.com/questions/30751151
复制相似问题