Listening for NgZone events
With the introduction of Angular 2 comes the concept of zones. Before you begin this recipe, I strongly recommended you to begin by working through the Working with zones outside Angular recipe.
zone.js
zone.js
is a library that Angular 2 directly depends upon. It allows Angular to be built upon a zone that allows the framework to intimately manage its execution context.
More plainly, this means that Angular can tell when asynchronous things are happening that it might care about. If this sounds a bit like how $scope.apply()
was relevant in Angular 1.x, you are thinking in the right way.
NgZone
Angular 2's integration with zones takes the form of the NgZone
service, which acts as a sort of wrapper for the actual Angular zones. This service exposes a useful API that you can tap into.
Note
The code, links, and a live example related to this recipe are available at http://ngcookbook.herokuapp.com/8676/.
Getting ready
All that is needed for this recipe is a component into...