我正在使用Angular 4和Angular Google Maps。在Angular 4中集成Angular Google Maps:页面重新加载错误
我跟着指示在the getting started page,但每次我重新加载页面,而我在地图上来看,我得到的错误:You have included the Google Maps API multiple times on this page. This may cause unexpected errors.
这是我的代码的执行:
- 地图.component.html
<div class="container">
<agm-map [latitude]="lat" [longitude]="lng">
<agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>
</div>
- map.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
private lat: number = 2.3522;
private lng: number = 48.8566;
constructor() { }
ngOnInit() {
}
}
- app.module.ts
//...
import { AgmCoreModule } from '@agm/core';
//...
import { MapComponent } from './map/map.component';
//...
@NgModule({
declarations: [
//...
MapComponent
],
imports: [
//...
AgmCoreModule.forRoot({
apiKey: MY_KEY
}),
//...
],
providers: [
//...
],
bootstrap: [AppComponent]
})
export class AppModule {
}
platformBrowserDynamic().bootstrapModule(AppModule);
请注意,如果我从另一个视图导航到地图视图时没有此错误,但每当我在地图视图中重新加载页面时,错误都显示在浏览器控制台中。
是否错误的效果的功能/页面是否还在加载?另外,可以肯定的是,你没有使用路由器或任何改变URL的东西?当你重新加载页面时,它从浏览器中的相同url重新加载?或者这是在本地生产版本? – diopside
@diopside当我遇到这个问题时,页面无法加载,只有当我导航到另一个视图然后返回到地图时,才访问我的地图视图。是的,页面是从浏览器中的相同URL重新加载的。这种情况会发生,要么是我手动重新加载,要么是angular-cli在开发环境中自动重建应用程序并在浏览器中重新加载页面 – Strider
@diopside关于路由,我没有使用任何特殊的东西:'{path:'map',组件:MapComponent' – Strider