【问题标题】:Access angular NgZone instance from window.object从 window.object 访问角度 NgZone 实例
【发布时间】:2018-05-17 02:11:33
【问题描述】:

是否可以访问 angular(2+) ZoneJS 实例 (NgZone) 无需注入 它在 constructor 里面是这样的:

...

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

现在,当我开发我的 Angular 库时,我需要这样做:

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

但我不想让用户关心 NgZone 的初始化。

【问题讨论】:

  • 另外我不想使用注入器angular.io/api/core/Injector 来保持库框架的独立性。
  • ng.coreTokens.NgZone
  • 对不起@yurzui,但这不是一个实例...

标签: angular zone ngzone


【解决方案1】:

您可以使用以下代码获取NgZone 实例:

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

另见

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-20
  • 1970-01-01
  • 1970-01-01
  • 2018-06-13
  • 2023-04-02
  • 1970-01-01
相关资源
最近更新 更多