下面的代碼演示zone.js功能:無法從<a href="https://github.com/angular/zone.js/" rel="nofollow noreferrer">here</a>瞭解zone.js例如
Zone.current.fork({}).run(function() {
Zone.current.inTheZone = true;
setTimeout(function() {
console.log('in the zone: ' + !!Zone.current.inTheZone);
}, 0);
});
console.log('in the zone: ' + !!Zone.current.inTheZone);
上面將記錄:
'in the zone: false'
'in the zone: true'
我真的不明白它是什麼該區域正在這裏做,它與截獲this video談到的事件有什麼關係。
它輸出false
第一次因爲Zone.current.inTheZone
爲undefined
,因爲我們改變Zone.current.inTheZone = true;
,現在是被ouputted第二時間的價值。有什麼特別的是zone
在這裏做?
它可以幫助你瞭解http://blog.thoughtram.io/angular/2016/01/22/understanding-zones.html –