The peeskillet site shows how to exclude EventListener from ChangeDetection:
import { Component, NgZone } from '@angular/core';
@Component(...)
export class AppComponent {
...
element: HTMLElement;
constructor(private zone: NgZone) {}
mouseDown(event) {
...
this.element = event.target;
this.zone.runOutsideAngular(() => {
window.document.addEventListener('mousemove', this.mouseMove.bind(this));
});
}
mouseMove(event) {
event.preventDefault();
this.element.setAttribute('x', event.clientX + this.clientX + 'px');
this.element.setAttribute('y', event.clientX + this.clientY + 'px');
}
}
For more information, I really recommend this article . Great thx for peeskillet!
source
share