我正在尝试在 Angular 4 中制作 bing 组件,但它根本不允许我渲染 map ..
这是我的index.html 文件:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Microsoft</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=experimental'></script>
</head>
<body onload="AppComponent.helloWorld()">
<div id="myMap"></div>
<app-root></app-root>
</body>
</html>
这是我的组件:
export class AppComponent implements OnInit {
@ViewChild('myMap') myMap;
title = 'app';
ngOnInit() {
if(Microsoft !== undefined){
var map = new Microsoft.Maps.Map(this.myMap.nativeElement, {
credentials: 'key goes here'
});
}}
}
组件 HTML 文件:
<div #myMap style='width: 100%; height: 500px;'></div>
我不知道我做错了什么。但我无法加载 map 。它抛出无法读取空错误的属性“原型(prototype)”。
最佳答案
执行ngOnInit()
时,#myMap不存在,因此将代码移至ngAfterViewChecked()
。
关于javascript - 无法读取 null bing map 和 Angular4 的属性 'prototype',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45825732/