From the course: Creating Angular Libraries

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Avoiding zone pollution

Avoiding zone pollution - Angular Tutorial

From the course: Creating Angular Libraries

Avoiding zone pollution

- [Narrator] Zone pollution happens when Angular runs change detection on code that doesn't need it. Too many change detection cycles can slow down your application and make your UI sluggish. Third party libraries are a common source of zone pollution, especially when they set up their own event listeners, call set timeout or set interval or run code inside a request animation frame. The best way to find the source of your pollution is by using Angular dev tools, an open source browser extension maintained by the official Angular team. The profiler tab lets you visualize Angular's change detection in real time. Zone pollution may appear as large consecutive columns with a source of set timeout, set interval, request animation frame, or an event handler. Once you find the source, the best way to fix it is to disable Angular's change detection. There are a few ways to do this. The simplest way is to use the on push change detection strategy for a component. This tells Angular to check…

Contents