1

In AngularJS 2, most zone-related examples and articles center on the zone object and functions like zone.fork and zone.run. For example, this article and this video focus on the zone object.

But the AngularJS 2 documentation presents a class named NgZone. I'd like to use methods like onTurnStart and onTurnDone, but I can't find any examples of these methods being used. Should I bother using this class at all?

SnareChops
  • 13,175
  • 9
  • 69
  • 91
MatthewScarpino
  • 5,672
  • 5
  • 33
  • 47

1 Answers1

3

In Angular2 the NgZone class is a wrapper around the zone.js framework. Also the dependency injector will pass in the zone that relates to that component.

So the answer is: If you are going to use zone at all. Then definitely use NgZone.

The documentation for NgZone can be found here including all of the methods and their arguments.

SnareChops
  • 13,175
  • 9
  • 69
  • 91
  • I see that, but there's just so much documentation and example code available for zone and almost nothing for NgZone. If no one else is using NgZone, why should I? – MatthewScarpino Jan 27 '16 at 02:11
  • `NgZone == zone` essentially. You can use the docs for `zone` in conjunction with `NgZone` provided that the method exposed is the same. – SnareChops Jan 27 '16 at 02:12
  • Thanks, but the only method they have in common is run. And the Angular2 documentation doesn't explain what a microtask is or show how onTurnStart/onTurnDone/onEventDone are expected to be used. I'll stick with zone for now, and use NgZone when there's more (some) documentation. – MatthewScarpino Jan 27 '16 at 02:20
  • @user934904 check this [article](http://blog.thoughtram.io/angular/2016/01/22/understanding-zones.html) from Pascal Precht. Note as well that Zone was proposed to TC39, see this [presentation](https://docs.google.com/presentation/d/1H3E2ToJ8VHgZS8eS6bRv-vg5OksObj5wv6gyzJJwOK0/edit#slide=id.g105c754704_1_55) (sadly just slides, no video) – Eric Martinez Jan 27 '16 at 02:45
  • @Eric, thanks. I read the article and the presentation, but neither mention the NgZone class and its methods. I'd like to know if there's a way to fork a new zone from an NgZone, but it looks like you need zone.fork. – MatthewScarpino Jan 27 '16 at 03:12
  • ^^ I'm wondering the same thing @user934904. Did you ever figure it out? – Dan Rasmuson Jun 22 '16 at 17:48