javascript - 尽管在区域外运行超时,Chrome DevTools 中的 NgZone 超时警告

标签 javascript angular timeout google-chrome-devtools angular2-changedetection

在 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/

相关文章:

javascript - Cinnamon desklet 不接受更改

javascript - jQuery DataTable 响应式不适用于 Bootstrap 3

如果没有响应,C 套接字将关闭连接

html - 如何在 Angular 4 中为表格添加分页?

javascript - 在 Material <md-tab-group> 中使用 Angular 2 组件

.net - Browser.AttachTo<T>() 导致间歇性异常 "Timeout while Internet Explorer busy"

c# SerialPort WriteTimeout 使用?

javascript - 添加太多事件监听器会影响性能吗?

javascript - 我可以使用什么 javascript 代码/库从网页中包含的小型 iframe 打开浏览器窗口弹出窗口?

angular - 通过 Angular2 中的嵌套组件发出事件