将zonejs“监听"到黑色Angular 8中polyfills.ts中的事件列表不起作用 [英] Black the zonejs "listening" event list in polyfills.ts in Angular 8 not working

查看:73
本文介绍了将zonejs“监听"到黑色Angular 8中polyfills.ts中的事件列表不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找出如何停止Angular中的 mousemove 事件触发更改检测.有些文章提到,我可以通过在 polyfills.ts 中添加一行来实现此目的:
(任意窗口).__zone_symbol__BLACK_LISTED_EVENTS = ['mousemove'];

I've been trying to figure out how to stop mousemove event firing change detection in Angular. Some articles mentioned I can achieve this by adding a line in polyfills.ts:
(window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['mousemove'];

我已经在 stackblitz 中进行了尝试,并且效果很好.但是,棘手的部分是,如果我在本地创建一个Angular项目并执行完全相同的操作,则根本无法使用.即使我在 polyfills.ts 中添加了以上代码,它也始终会在mousemove事件上触发更改检测.

I've tried it in stackblitz and it perfectly works. BUT, the tricky part is that it doesn't not work at all if I create a Angular project in my local and do totally the same thing. It just keeps triggering change detection on mousemove event even though I add the line above in polyfills.ts.

我想念什么?任何见识将不胜感激!

What am I missing? Any insight would be appreciated!

推荐答案

感谢@jialipassion,设法将其钉住.

Thanks to @jialipassion, managed to nail it.

  1. 使用 polyfills.ts
  2. 在同一级别上创建一个新文件 zone-flag.ts
  3. 添加(任意窗口).__zone_symbol__BLACK_LISTED_EVENTS = ['mousemove']; zone-flag.ts 中:

在zone-flag.ts中的

// in zone-flag.ts
(window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['mousemove'];

  1. polyfills.ts 中添加 import'./zone-flag':

// in polyfills.ts
import './zone-flag';
import 'zone.js/dist/zone'; // Included with Angular CLI.

希望这对可能在此处导航的人有所帮助.

Hope this help anyone who might navigate here.

这篇关于将zonejs“监听"到黑色Angular 8中polyfills.ts中的事件列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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