错误没有NgZone的提供者

时间:2017-12-17 20:56:01

标签: angular maps angular-google-maps angularjs-injector ngzone

我有一个使用Angular Google Maps来显示位置的应用程序。一开始我能够显示地图,但是一段时间(可能是我修改了一些东西)我收到以下错误:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[NgZone]: 
StaticInjectorError[NgZone]: 
NullInjectorError: No provider for NgZone!
at _NullInjector.get (core.js:923)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)
at resolveNgModuleDep (core.js:10585)
at NgModuleRef_.get (core.js:11806)
at resolveDep (core.js:12302)
at _NullInjector.get (core.js:923)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)
at resolveNgModuleDep (core.js:10585)
at NgModuleRef_.get (core.js:11806)
at resolveDep (core.js:12302)
at resolvePromise (zone.js:824)
at resolvePromise (zone.js:795)
at eval (zone.js:873)
at ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.js:4620)
at ZoneDelegate.invokeTask (zone.js:424)
at Zone.runTask (zone.js:192)
at drainMicroTaskQueue (zone.js:602)
at <anonymous>

我的代码是: app.module.ts:

import { AgmCoreModule } from '@agm/core';

imports AgmCoreModule.forRoot({apiKey:'...'})

mycomponent.html

<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
    <agm-marker [latitude]="lat" [longitude]="lng">
        <agm-info-window>
            <div>
                my text
            </div>
        </agm-info-window>
    </agm-marker>

我真的很感谢你的帮助!

2 个答案:

答案 0 :(得分:3)

您可以手动提供NgZone

import { NgZone } from '@angular/core';

@NgModule({
    providers: [
        // ...
        { provide: NgZone, useFactory: () => new NgZone({}) }
    ]
})

答案 1 :(得分:0)

您需要在所有正在使用的库中添加peerDependencies。

还可以通过从导入中删除每个模块的方式进行检查,以查看引起问题的模块。 此 link 应该会有所帮助。