使用zone.js从任何地方检测当前执行上下文? [英] Use zone.js to detect current execution context from anywhere?

查看:130
本文介绍了使用zone.js从任何地方检测当前执行上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 zone.js 是有可能从的任何地方确定当前执行上下文?即,如果一个区域绑定函数调用它调用另一个函数的setTimeout(myFn)我可以从内部 myFn确定当前执行上下文()?如果有,请提供如何做一个简单的例子。

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.

推荐答案

每次叉() A ,访问内的<对象STRONG>区的情况下将始终返回分叉

Every time you fork() a zone, accessing the zone object within that zone's context will always return the forked zone.

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:

这篇关于使用zone.js从任何地方检测当前执行上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆