【发布时间】:2016-09-16 12:45:25
【问题描述】:
我有一个 Angular 2 组件,它以如下方式在文件 comp.ts 中定义:
import {Component} from 'angular2/core';
@component({
selector:'my-comp',
templateUrl:'comp.html'
})
export class MyComp{
constructor(){
}
}
因为我想让组件显示谷歌地图,所以我在文件 comp.html 中插入了以下代码:
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
此代码已从此链接http://www.w3schools.com/googleAPI/google_maps_basic.asp 复制。问题是组件不显示地图。我做错了什么?
【问题讨论】:
标签: google-maps angular angular2-template