Access angular NgZone instance from window.object

自古美人都是妖i 提交于 2021-02-07 09:45:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!