With zone.js is it possible to determine the current execution context from anywhere? Ie., if a zone-bound function calls another function which calls setTimeout(myFn) can I determine the current execution context from within myFn()? If so, please provide a simple example of how to do so.
Asked
Active
Viewed 1,584 times
1
Gil Birman
- 35,242
- 14
- 75
- 119
1 Answers
1
Every time you fork() a zone, accessing the zone object within that zone's context will always return the forked zone.
The following experiment demonstrates this behavior:
var b = function() { console.log('-->',zone) };
var a = function() { setTimeout(b,5); };
zone.fork().run(function() { zone.x = 'hi'; a(); });
setTimeout(function() { console.log('==>', zone); }, 1);
setTimeout(function() { console.log('==>', zone); }, 10);
Here's what happens when you paste it into the console:

Gil Birman
- 35,242
- 14
- 75
- 119