【问题标题】:Failed to execute 'write' on 'Document' error in loading angular google map加载角度谷歌地图时无法在“文档”错误上执行“写入”
【发布时间】:2015-05-26 08:36:04
【问题描述】:
我在 Web 开发项目中使用 angularjs 并使用 Angular Google Maps
向我推荐了 api 用于将谷歌地图添加到我的项目中。
这是非常有用的 api,但是当我使用 this 快速启动将它加载到我的项目中时,它会崩溃一段时间并向我抛出这个异常:
在“文档”上执行“写入”失败:无法写入
从异步加载的外部脚本到文档中,除非
它是显式打开的。
有时它工作得很好。我在谷歌搜索,现在我知道这个问题是因为加载页面后加载谷歌地图。任何人都可以帮助我找到在异步加载后将地图加载到部分 html 表单的解决方案吗?
【问题讨论】:
-
也许您应该直接尝试文档。 doc。这是一个类似的问题:Link。希望这可以给你一个参考。
标签:
javascript
angularjs
google-maps
【解决方案1】:
在您的 api 请求中指定 &callback=someWindowFunction,document.write 将不会被调用
var _this = this;
window["googleMapsLoad"] = function () {
_this.googleMapsLoaded = true;
if (_this.initialized) {
_this.reportReady();
_this.createMap();
}
};
this.initialize = function (reportReady) {
this._super(false);
if (this.googleMapsLoaded) {
this.reportReady();
this.createMap();
}
};
var script = document.createElement("script");
script.src = "//maps.googleapis.com/maps/api/js?callback=googleMapsLoad";
document.head.appendChild(script);