在 Chrome DevTools 中仍然收到警告是否正常
[Violation] 'setTimeout' handler took 103ms zone.js:1894
即使您在 ngzone 之外运行所有超时?我这样做:
this.zone.runOutsideAngular(() => {
this._timeout = setTimeout(() => {
// ...
});
});
并清除现有的 onDestroy 超时(Angular)
最佳答案
setTimeout
在 Angular 之外运行的事实并不意味着它在区域之外运行。
作为the reference州,
Executes the fn function synchronously in Angular's parent zone and returns value returned by the function.
Running functions via runOutsideAngular allows you to escape Angular's zone and do work that doesn't trigger Angular change-detection or is subject to Angular's error handling.
所以预计 setTimeout
仍然在一个区域内运行。
关于javascript - 尽管在区域外运行超时,Chrome DevTools 中的 NgZone 超时警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47199657/