1

I have seen this used by test frameworks (for example, Arquillian) to detect when the dom is ready to be examined with Angular 1. Is there an equivalent way to do this in angular 2?

jsight
  • 27,819
  • 25
  • 107
  • 140

1 Answers1

1

onEventDone from NgZone should work for that

Notifies subscribers immediately after the final onTurnDone callback before ending VM event.

This event is useful for validating application state (e.g. in a test).

https://angular.io/api/core/NgZone

Evan Wieland
  • 1,445
  • 1
  • 20
  • 36
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I think that this is the right answer, but how do I get access to the NgZone (or at least the injector itself) from outside of Angular? – jsight Mar 10 '16 at 20:13
  • I'm searching some time already but I haven't found example code and I haven't used it myself yet. This might work https://github.com/angular/angular/blob/14f0e9ada8b23e6cb4dd4cf4ce1127e9c9180476/modules/angular2/test/core/zone/ng_zone_spec.ts. In `beforeEach()` create a zone and then run your test in `_zone.run(...)`. – Günter Zöchbauer Mar 10 '16 at 20:18
  • Ah, I can get the root injector by assigning the result of calling bootstrap to window.app. That makes it possible to get to window.app.injector from what I would think that I could lookup NgZone. I haven't figured out the next step, though. – jsight Mar 10 '16 at 21:19
  • Zone should allow to subscribe to `onTurnDone()` – Günter Zöchbauer Mar 10 '16 at 21:21
  • I ended up grabbing it from the injector and assigning it to Window. window["MainNgZone"] = app.injector.get(NgZone); This can be done in the callback from bootstrap. – jsight Mar 10 '16 at 22:15
  • So, you got it working? Would be great if you could post what you've learned. – Günter Zöchbauer Mar 11 '16 at 18:07