执行'write'& # 39;文档# 39;加载角度谷歌地图时出错

Failed to execute 'write' on 'Document' error in loading angular google map

本文关键字:谷歌地图 出错 加载 执行 文档 write      更新时间:2023-09-26

我在一个web开发项目中使用angularjs,并使用Angular谷歌地图API被推荐给我添加谷歌地图到我的项目。这是一个非常有用的API,但是当我在我的项目中使用这个快速启动加载它时,它崩溃了一段时间,并抛出这个异常给我:

对'Document'执行'write'操作失败:无法写入从异步加载的外部脚本导入文档,除非

,有时它工作得很好。我在谷歌搜索,现在我知道这个问题是因为加载页面后加载谷歌地图。任何人都可以帮助我找到一个解决方案,加载映射到部分HTML表单后异步加载?

在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);