Skip to content

Commit

Permalink
Update to Angular 9 support. Ivy currently is a challenge due to unim…
Browse files Browse the repository at this point in the history
…plemented findProviders() function. Code in place to support it now, but won't work for Ivy yet.
  • Loading branch information
DanWahlin committed Feb 16, 2020
1 parent add9647 commit 5a9f089
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
Expand All @@ -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);
}
}

}

0 comments on commit 5a9f089

Please sign in to comment.