2

I am currently working with Angular 4 which uses zone.js natively to monitor activity on the DOM.

In my Angular application I am getting zone.js errors: [Violation] 'keydown' handler took 209ms - zone.js

I do not want to disable zone.js from Angular all together, but would like to disable specific functionality of zone.js to prevent it from placing the EventListener on 'keydown' functionality.

I am using the latest version 08.14 of zone.js and any help to disable or modify zone.js to prevent it from monitoring this specific activity would be greatly appreciated.

In Angular, the simple usage of "RemoveEventListener" will not Remove EventHandlers placed by zone.js. This requires something specific to zone.js

dbrant
  • 21
  • 3
  • While I can see how disabling some kinds of monitoring could be convenient, I would first ask what could be causing the keydown handler to take an entire 209 ms to be processed; this may point to a design flaw. – Haroldo_OK Mar 15 '18 at 13:27
  • That is a great question. It seems to be something related to zone.js associating this event handler to the DOM. When the size of the DOM gets large, this is one of the errors that occurs. While I don't like it, it helps to isolate the issue (disable) and then attempt to resolve. – dbrant Mar 17 '18 at 15:22

1 Answers1

0

if you can upgrade to the latest version of zone.js(0.8.20), you can set this flag in polyfill.ts before loading zone.js

(window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['keydown'];

And I believe you don't need to upgrade your version of angular.

jiali passion
  • 1,691
  • 1
  • 14
  • 19
  • Could you provide any reproduce repo? Or you can post an issue in angular repo. – jiali passion Oct 23 '19 at 07:54
  • The weird thing is that the above approach perfectly works in stackblitz but it doesn't when I create an angular app with cli and do the same thing. I've opened an issue about it https://stackoverflow.com/questions/58517069/black-the-zonejs-listening-event-list-in-polyfills-ts-in-angular-8-not-working – DongBin Kim Oct 23 '19 at 08:14