【发布时间】:2018-03-24 17:10:33
【问题描述】:
我已经看到这个问题被问了 100 次,但似乎没有一个答案有效。我正在尝试像这样声明一个类:
class Popup extends google.maps.OverlayView {
// Classy stuff
}
但我总是收到错误Uncaught ReferenceError: google is not defined
问题是,Google 地图在我的代码中的其他任何地方都可以使用,但在我声明此类时却不行。另外,我在这样的课程之后声明它:
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss',]
})
export class MapComponent implements AfterViewInit, OnDestroy {
map: google.maps.Map; <-- No problem with google namespace here
// Map stuff
}
class Popup extends google.maps.OverlayView { <-- Problem is with this google namespace
// Classy stuff
}
我刷新页面,有时它会加载,有时会崩溃并给我这个错误。
我正在像这样加载我的 index.html:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=myKey&libraries=places"></script>
它总是有效(我在整个项目中都使用谷歌地图,并且还没有遇到任何其他谷歌命名空间的问题。就在我尝试创建该类时)
【问题讨论】:
标签: angular google-maps typescript