Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access angular NgZone instance from window.object

Is it possible to access angular(2+) ZoneJS instance (NgZone) without injecting it inside constructor like this:

...

 const zone = window['<angular zonejs path in window object>']
...

For now when I developing my angular library I need to do this:

class Test {
 constructor( zone: NgZone ) { initmyplugin(zone); }
}

But I don't wanna user to care about initialization of NgZone.

like image 240
Dariusz Filipiak Avatar asked Jul 14 '26 04:07

Dariusz Filipiak


1 Answers

You can get hold of NgZone instance by using the following code:

ng.probe(getAllAngularRootElements()[0]).injector.get(ng.coreTokens.NgZone)

See also

  • Trigger Angular change detection from console
like image 72
yurzui Avatar answered Jul 15 '26 22:07

yurzui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!