无法在页面中显示地图

时间:2018-10-09 13:29:14

标签: angular google-maps

我正在关注Angular Google Maps文档,并遵循 ERROR TypeError:Object(...)不是函数。

这是MapModule

import { NgModule } from '@angular/core';
import {MapComponent} from './map.component';
import { AgmCoreModule } from '@agm/core';

@NgModule({
  declarations: [
    MapComponent
  ],
  exports: [
      MapComponent
  ],
  imports: [
    AgmCoreModule.forRoot({
        apiKey: '*******************'
      })
  ],
  providers: [],
})
export class MapModule { }

MapHtml

<agm-map [latitude]="lat" [longitude]="lng">
  <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>

MapSCSS

agm-map {
    height: 300px;
  }

MapComponent

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'bwm-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {

  lat: number = 51.678418;
  lng: number = 7.809007;
  constructor() { }

  ngOnInit() {
  }

}

我正在使用Angular版本6 ... AGM版本:@ agm / core @ 1.0.0-beta.5

1 个答案:

答案 0 :(得分:1)

您没有提供错误堆栈,但我想它与此类似:

  

TypeError:Object(...)不是函数       在新的FitBoundsService(webpack-internal:///../../../../@agm/core/services/fit-bounds.js:38)       在createClass(webpack-internal:///../../../core/esm5/core.js:12697)       在_createProviderInstance(webpack-internal:///../../../core/esm5/core.js:12674)       在createProviderInstance(webpack-internal:///../../../core/esm5/core.js:12515)上       在createViewNodes(webpack-internal:///../../../core/esm5/core.js:13987)       在callViewAction(webpack-internal:///../../../core/esm5/core.js:14434)       在execComponentViewsAction(webpack-internal:///../../../core/esm5/core.js:14343)       在createViewNodes(webpack-internal:///../../../core/esm5/core.js:14028)       在createRootView(webpack-internal:///../../../core/esm5/core.js:13889)       在callWithDebugContext(webpack-internal:///../../../core/esm5/core.js:15314)

您很有可能正在创建Angular:5应用程序,该应用程序将安装RxJS 5.x软件包。 但是从@agm/core@1.0.0-beta.4开始,库对RxJS 6.x有依赖性,这就是发生此错误的原因。

因此,一种解决方案将是update RxJS from from 5.x to 6.x

npm uninstall rxjs
npm install rxjs@6 rxjs-compat@6 --save

另一种选择是将@agm/core降级至版本:1.0.0-beta.3,该版本与RxJS v5.x兼容

已报道类似问题here