angular - TypeError:无法读取未定义的属性“defaultView” - Angular
问题描述
我有一个运行时错误,它defaultView
在我的角度应用程序中给了我堆栈跟踪,它阻止我继续我的项目。
错误: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'defaultView' of undefined
TypeError: Cannot read property 'defaultView' of undefined
我已经用谷歌搜索了这个,但没有一个问题有角度。所以我认为这是第一个关于defaultView
角度的。
我有一些代码可以获取地址并将标记输出到地图上。我从https://developers.google.com/maps/documentation/javascript/geocoding收到错误
Stackblitz 中的代码:https ://stackblitz.com/edit/angular-gib2mq 。
根文件夹中的index.d.ts使 import 语句起作用:import { } from 'googlemaps';
declare module "googlemaps";
我也@types/googlemaps
通过安装npm install --save @types/googlemaps
我希望错误消失,但每次运行我的应用程序时都会发生这种情况。
谢谢!
解决方案
看起来你对如何使用 @agm 包有很大的误解。没关系!一些注意事项:
- 您不需要 this.map 或 latlng 类型。您只需将数字传递给组件
- 需要居中时在地图上调用 triggerResize(true)
- 您不需要在配置中显式导入库...不确定为什么会这样。只需确保您使用的 API 密钥已启用它们
- 最后,您需要给地图一个静态高度,或者它的父级需要一个(我不会进入的 css 原因)。您始终可以使用打字稿设置高度。
工作 stackblitz(减去 API 密钥):https ://stackblitz.com/edit/angular-yebacm
祝你好运!
编辑:你也不需要declare module "googlemaps";
推荐阅读
- c# - asp.net 核心自定义身份验证,生成的令牌没有会话
- java - 从 getName 特定字符替换特定字符和 setText
- javascript - .Net Core POST 请求数组大小限制
- javascript - JavaScript 函数更改对象参数和所有相关变量
- gtk3 - 如何在回调中使用结构的参数化成员函数?
- mysql - mysql 选择条件
- php - 如何修复我的解析器在 PHP 和 CURL 上的无休止工作?
- sql - 当一个项目=这个另一个项目可以=这个或那个时的where子句:案例陈述?
- python - 如何一次循环遍历不同的配置文件?
- java - Android Studio - 我无法弄清楚是什么导致我的 StringArray 返回 NullPointerException,因为它记录为已初始化和已填充