diff --git a/modules/observable-store-extensions/angular/angular-devtools-extension.ts b/modules/observable-store-extensions/angular/angular-devtools-extension.ts index fe51b31..95d7209 100644 --- a/modules/observable-store-extensions/angular/angular-devtools-extension.ts +++ b/modules/observable-store-extensions/angular/angular-devtools-extension.ts @@ -1,19 +1,38 @@ export class AngularDevToolsExtension { private window = (window as any); - private rootElements: any; private router: any; private ngZone: any; constructor() { - this.rootElements = this.window.ng.probe(this.window.getAllAngularRootElements()[0]); - const providers = this.rootElements.injector.view.root.ngModule._providers; - this.router = providers.find(p => p && p.constructor && p.constructor.name === 'Router'); + + // Angular with NO Ivy + if (this.window.ng.probe) { + const rootElements = this.window.ng.probe(this.window.getAllAngularRootElements()[0]); + const providers = rootElements.injector.view.root.ngModule._providers; + this.router = providers.find(p => p && p.constructor && p.constructor.name === 'Router'); + try { + this.ngZone = rootElements.injector.get(this.window.ng.coreTokens.NgZone); + } + catch (e) { + console.log(e); + } + } - this.ngZone = this.getNgZone(); + // Angular with Ivy + if (this.window.getAllAngularTestabilities) { + const testabilities = this.window.getAllAngularTestabilities()[0]; + this.router = testabilities.findProviders(this.window.getAllAngularRootElements()[0], 'Router'); + try { + this.ngZone = testabilities._ngZone; + } + catch (e) { + console.log(e); + } + } } navigate(path: string) { - if (this.ngZone) { + if (this.ngZone && this.router) { this.runInZone(() => { this.router.navigateByUrl(path); }); @@ -28,13 +47,4 @@ export class AngularDevToolsExtension { } } - private getNgZone() { - try { - return this.rootElements.injector.get(this.window.ng.coreTokens.NgZone); - } - catch (e) { - console.log(e); - } - } - } \ No newline at end of file