-
Notifications
You must be signed in to change notification settings - Fork 1
/
undetected.event.ts
45 lines (39 loc) · 1.08 KB
/
undetected.event.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {Inject, Injectable} from "@angular/core";
import {DOCUMENT} from "@angular/common";
import {MyEventManagerPlugin} from "../__util/event-manager-plugin";
/**
* Listen to events without triggering change detection
*
* Usage:
* <button (undetected.click)="handleClick()"></button>
*
* ...
*
* export class ExampleComponent implements OnInit {
*
* constructor(private zone: NgZone) {}
*
* handleClick() {
* if(someCondition) {
* this.zone.run(() => {
* ...
* });
* }
* }
* }
*
*/
@Injectable()
export class UndetectedEventPlugin extends MyEventManagerPlugin {
constructor(@Inject(DOCUMENT) doc: any) {
super(doc)
}
supports(eventName: string): boolean {
return eventName.indexOf('undetected.') === 0;
}
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
const realEventName = eventName.slice(11);
return this.manager.getZone().runOutsideAngular(() =>
this.manager.addEventListener(element, realEventName, handler));
}
}