Skip to content

Commit 5de65e7

Browse files
author
Umed Khudoiberdiev
authored
Merge pull request pleerock#49 from PickleyD/master
Universal Angular 2 support.
2 parents 5cc1cf0 + deb734b commit 5de65e7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/PopoverContent.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Input, AfterViewInit, ElementRef, ChangeDetectorRef, OnDestroy, ViewChild, EventEmitter} from "@angular/core";
1+
import {Component, Input, AfterViewInit, ElementRef, ChangeDetectorRef, OnDestroy, ViewChild, EventEmitter, Renderer } from "@angular/core";
22
import {Popover} from "./Popover";
33

44
@Component({
@@ -102,28 +102,31 @@ export class PopoverContent implements AfterViewInit, OnDestroy {
102102
// -------------------------------------------------------------------------
103103

104104
constructor(protected element: ElementRef,
105-
protected cdr: ChangeDetectorRef) {
105+
protected cdr: ChangeDetectorRef,
106+
protected renderer: Renderer) {
106107
}
107108

108109
// -------------------------------------------------------------------------
109110
// Lifecycle callbacks
110111
// -------------------------------------------------------------------------
111112

113+
listenClickFunc: any;
114+
listenMouseFunc: any;
112115
ngAfterViewInit(): void {
113116
if (this.closeOnClickOutside)
114-
document.addEventListener("mousedown", this.onDocumentMouseDown);
117+
this.listenClickFunc = this.renderer.listenGlobal("document", "mousedown", (event: any) => this.onDocumentMouseDown(event));
115118
if (this.closeOnMouseOutside)
116-
document.addEventListener("mouseover", this.onDocumentMouseDown);
119+
this.listenMouseFunc = this.renderer.listenGlobal("document", "mouseover", (event: any) => this.onDocumentMouseDown(event));
117120

118121
this.show();
119122
this.cdr.detectChanges();
120123
}
121124

122125
ngOnDestroy() {
123126
if (this.closeOnClickOutside)
124-
document.removeEventListener("mousedown", this.onDocumentMouseDown);
127+
this.listenClickFunc();
125128
if (this.closeOnMouseOutside)
126-
document.removeEventListener("mouseover", this.onDocumentMouseDown);
129+
this.listenMouseFunc();
127130
}
128131

129132
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)