问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/47619350/access-angular-ngzone-instance-from-window-object