Angular-google-maps: 无法在页面中显示地图。 错误类型错误:Object(...) 不是函数

创建于 2018-09-27  ·  22评论  ·  资料来源: SebastianM/angular-google-maps

我完全按照入门中的步骤操作,但是在页面加载过程中出现错误并且无法加载地图。

重现步骤
1)通过终端安装agm核心模块
npm install @agm/core --save

2) 在app.module.ts包含 AgmCoreModule

```
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AgmCoreModule } from '@agm/core';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        AgmCoreModule.forRoot({
          apiKey : 'my_api_key'
        })
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }
```

3) 在我的 html 中添加<agm-map />组件

```
<agm-map [latitude]="latitude" [longitude]="longitude">
</agm-map>
```

4) 在我的app.component.scss<agm-map />组件添加高度
agm-map { height : 600px; }

5) 在app.component.ts添加latitudelongitude属性
``
从“@angular/core”导入{组件};

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent {
    latitude: number = 51.678418;
    longitude: number = 7.809007;

    constructor(){}

}
```

6) 使用ng serve命令运行应用程序
7) 在我的浏览器中打开http://localhost:4200只是为了在开发者控制台中看到带有以下错误的空白页面。
ERROR TypeError: Object(...) is not a function at new FitBoundsService (fit-bounds.js:31) at createClass (core.js:12481) at _createProviderInstance (core.js:12458) at createProviderInstance (core.js:12299) at createViewNodes (core.js:13771) at callViewAction (core.js:14218) at execComponentViewsAction (core.js:14127) at createViewNodes (core.js:13812) at createRootView (core.js:13673) at callWithDebugContext (core.js:15098)

预期/期望行为
我想显示一张没有任何标记的地图。

angular2 和 angular-google-maps 版本

Angular CLI: 1.6.8
Node: 9.5.0
OS: linux x64
Angular: 5.2.11
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, language-service, platform-browser
    ... platform-browser-dynamic, router

@angular/cli: 1.6.8
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0

年度股东大会版本: @agm/[email protected]

最有用的评论

由于您正在创建 Angular: 5 应用程序:

Angular: 5.2.11

RxJS 5.x包随它一起安装。

但是从@agm/[email protected] ,库依赖于RxJS 6.x ,这就是发生此错误的原因。

因此,解决方案是将RxJS 从 5.x 更新为 6.x

npm uninstall rxjs
npm install rxjs<strong i="17">@6</strong> rxjs-compat<strong i="18">@6</strong> --save

所有22条评论

在 angular 6 中也是如此。它在 beta 4 中停止工作; beta 3 仍然可以正常工作。

同样在这里。

当我查看源映射时,对我来说,它在第 31 行抛出一个错误,它在FitBoundsService构造函数中设置了this.bounds$

import { Injectable } from '@angular/core';
import { BehaviorSubject, from, timer } from 'rxjs';
import { flatMap, map, sample, switchMap, shareReplay } from 'rxjs/operators';
import { MapsAPILoader } from './maps-api-loader/maps-api-loader';
/**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
var /**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
FitBoundsAccessor = /** <strong i="9">@class</strong> */ (function () {
    function FitBoundsAccessor() {
    }
    return FitBoundsAccessor;
}());
/**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
export { FitBoundsAccessor };
/**
 * The FitBoundsService is responsible for computing the bounds of the a single map.
 */
var FitBoundsService = /** <strong i="10">@class</strong> */ (function () {
    function FitBoundsService(loader) {
        var _this = this;
        this._boundsChangeSampleTime$ = new BehaviorSubject(200);
        this._includeInBounds$ = new BehaviorSubject(new Map());
        this.bounds$ = from(loader.load()).pipe(flatMap(function () { return _this._includeInBounds$; }), sample(this._boundsChangeSampleTime$.pipe(switchMap(function (time) { return timer(0, time); }))), map(function (includeInBounds) { return _this._generateBounds(includeInBounds); }), shareReplay(1));
    }
    FitBoundsService.prototype._generateBounds = function (includeInBounds) {
        var bounds = new google.maps.LatLngBounds();
        includeInBounds.forEach(function (b) { return bounds.extend(b); });
        return bounds;
    };
    FitBoundsService.prototype.addToBounds = function (latLng) {
        var id = this._createIdentifier(latLng);
        if (this._includeInBounds$.value.has(id)) {
            return;
        }
        var map = this._includeInBounds$.value;
        map.set(id, latLng);
        this._includeInBounds$.next(map);
    };
    FitBoundsService.prototype.removeFromBounds = function (latLng) {
        var map = this._includeInBounds$.value;
        map.delete(this._createIdentifier(latLng));
        this._includeInBounds$.next(map);
    };
    FitBoundsService.prototype.changeFitBoundsChangeSampleTime = function (timeMs) {
        this._boundsChangeSampleTime$.next(timeMs);
    };
    FitBoundsService.prototype.getBounds$ = function () {
        return this.bounds$;
    };
    FitBoundsService.prototype._createIdentifier = function (latLng) {
        return latLng.lat + "+" + latLng.lng;
    };
    FitBoundsService.decorators = [
        { type: Injectable },
    ];
    /** <strong i="11">@nocollapse</strong> */
    FitBoundsService.ctorParameters = function () { return [
        { type: MapsAPILoader, },
    ]; };
    return FitBoundsService;
}());
export { FitBoundsService };
//# sourceMappingURL=fit-bounds.js.map


// WEBPACK FOOTER //
// ./node_modules/@agm/core/services/fit-bounds.js.pre-build-optimizer.js

然而, @agm/[email protected]与 Angular 6.0.0 一起工作得很好。

我们也遇到了同样的错误。 以前有 "@agm/core": "^1.0.0- beta.2 " 正在安装 "@ core @1.0.0- agm / 1.0.0" -beta.5 ”。 这打破了我们的网站。
更改 package.json 以指定确切版本是我们目前的解决方法。 “@agm/core”:“1.0.0-beta.3”。

由于您正在创建 Angular: 5 应用程序:

Angular: 5.2.11

RxJS 5.x包随它一起安装。

但是从@agm/[email protected] ,库依赖于RxJS 6.x ,这就是发生此错误的原因。

因此,解决方案是将RxJS 从 5.x 更新为 6.x

npm uninstall rxjs
npm install rxjs<strong i="17">@6</strong> rxjs-compat<strong i="18">@6</strong> --save

@vgrem

@vgrem为我工作

@vgrem谢谢,为我工作。

尝试这个。 'npm i agm-core'。 这对我来说可以

@vgrem谢谢!!!

谢谢@vgrem
你的解决方案很棒,非常好

npm uninstall rxjs
npm install rxjs<strong i="7">@6</strong> rxjs-compat<strong i="8">@6</strong> --save

这对我来说非常有用。

由于您正在创建 Angular: 5 应用程序:

Angular: 5.2.11

RxJS 5.x包随它一起安装。

但是从@agm/[email protected] ,库依赖于RxJS 6.x ,这就是发生此错误的原因。

因此,解决方案是将RxJS 从 5.x 更新为 6.x

npm uninstall rxjs
npm install rxjs<strong i="18">@6</strong> rxjs-compat<strong i="19">@6</strong> --save

谢谢 !!!

没有为我工作。 我安装了rxjs@6rxjs-compat@6 ,但现在控制台中出现更多错误:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

我有 @agm/core 1.0.0-beta.5 和 @angular/core 5.2.11

帮助!

谢谢塞巴斯蒂安,非常好。

勒文。 1热。 2019 à 18:44,GioPetrucci通知@github.com a
评论:

没有为我工作。 我安装了rxjs@6rxjs-compat@6 ,但现在我有
控制台中的更多错误:

node_modules/rxjs/internal/types.d.ts(81,44) 中的错误:错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,74): 错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,77): 错误 TS1109: 预期表达。

我有 @agm/core 1.0.0-beta.5 和 @angular/core 5.2.11

帮助!


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-459805906
或静音线程
https://github.com/notifications/unsubscribe-auth/AsaAFdzd4L72QRQR6xX82u9UTBqZi_TTks5vJHzzgaJpZM4W8OOM
.

由于您正在创建 Angular: 5 应用程序:

角度:5.2.11

RxJS 5.x 包随它一起安装。

但是从@ agm / http://url/ 开始,该库有一个
对 RxJS 6.x 的依赖,这就是发生此错误的原因。

因此,解决方案是将 RxJS 从 5.x 更新到 6.x
https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md

npm 卸载 rxjs
npm 安装rxjs@6 rxjs-compat@6 --save

萨姆。 2热。 2019 à 09:24, Fouejio Georges [email protected]
一个écrit:

谢谢塞巴斯蒂安,非常好。

勒文。 1热。 2019 à 18:44,GioPetrucci通知@github.com a
评论:

没有为我工作。 我安装了rxjs@6rxjs-compat@6 ,但现在我有
控制台中的更多错误:

node_modules/rxjs/internal/types.d.ts(81,44) 中的错误:错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,74): 错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,77): 错误 TS1109: 预期表达。

我有 @agm/core 1.0.0-beta.5 和 @angular/core 5.2.11

帮助!


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-459805906
或静音线程
https://github.com/notifications/unsubscribe-auth/AsaAFdzd4L72QRQR6xX82u9UTBqZi_TTks5vJHzzgaJpZM4W8OOM
.

没有为我工作。 我安装了rxjs@6rxjs-compat@6 ,但现在控制台中出现更多错误:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

我有 @agm/core 1.0.0-beta.5 和 @angular/core 5.2.11

帮助!

同样在这里!

可能是,您有语法错误。 很好地检查你的代码

node_modules/rxjs/internal/types.d.ts(81,44) 中的 RROR:错误 TS1005:
';' 预期的。

我看到了 << ';' 预期的。 >>,检查你的语法,因为 Angular
像软代码。

如果错误仍然存​​在,请再次告诉我

勒文。 8热。 2019 à 13:18,亚历山德罗·奥利维拉·席尔瓦 <
通知@github.com> 一个 écrit :

没有为我工作。 我安装了rxjs@6rxjs-compat@6 ,但现在我有
控制台中的更多错误:

node_modules/rxjs/internal/types.d.ts(81,44) 中的错误:错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,74): 错误 TS1005: ';' 预期的。
node_modules/rxjs/internal/types.d.ts(81,77): 错误 TS1109: 预期表达。

我有 @agm/core 1.0.0-beta.5 和 @angular/core 5.2.11

帮助!

同样在这里!


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-461785390
或静音线程
https://github.com/notifications/unsubscribe-auth/AsaAFcrrjl40kD5DQkAsAU1hciR5kbjIks5vLWsLgaJpZM4W8OOM
.

@joker7blue任何解决方法?

我认为您在 package.json 中使用了这样的依赖项:
"@agm/core": "^1.0.0-beta.2"
当您使用^ ... npm 将优化您的依赖项,尝试使该软件包保持最新状态,直到该软件包与其他软件包兼容...但在这种情况下,npm 认为是错误的

我使用了这种语法,并且 npm 安装了 beta.5 .... 如果您在 node_modules 中搜索 agm 文件夹并打开 agm 的 package.json,您可以检查这一点.. 有一个“版本”键。

如果我删除版本号之前的^ ,我会强制 npm 使用这个版本,这解决了我的问题。

我希望它有帮助。

是的,我使用了"@agm/core": "1.0.0-beta.3" ,现在可以使用了。

也为我工作。
谢谢你。

可能是,您有语法错误。 在 node_modules/rxjs/internal/types.d.ts(81,44): 错误 TS1005: ';' 中很好地检查你的代码 RROR 预期的。 我看到了 << ';' 预期的。 >>,检查你的语法,因为 Angular 喜欢软代码。 如果错误仍然存​​在,请再次告诉我 Le ven。 8热。 2019 à 13:18,Alessandro Oliveira Silva <[email protected]> 一个écrit:

没有为我工作。 我安装了@* 和@ ,但现在我在控制台中有更多错误: node_modules/rxjs/internal/types.d.ts(81,44) 中的错误:错误 TS1005: ';' 预期的。 node_modules/rxjs/internal/types.d.ts(81,74): 错误 TS1005: ';' 预期的。 node_modules/rxjs/internal/types.d.ts(81,77): 错误 TS1109: 预期表达。 我有@agm/core 1.0.0-beta.5 和@angular/core 5.2.11 *帮助! 同样在这里! — 您收到此消息是因为您发表了评论。 直接回复本邮件,在 GitHub 上查看 < #1511(评论) >,或将线程静音https://github.com/notifications/unsubscribe-auth/AsaAFcrrjl40kD5DQkAsAU1hciR5kbjIks5vLWsLgaJpZM4W8OOM

它使用“推断”,这是在 2.8 中的 TypeScript 中引入的。 通过 package.json 和 npm install 更新 TypeScript 版本对我有用。

结束,因为 AGM 没有错误。

此页面是否有帮助?
0 / 5 - 0 等级