|
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"; |
2 | 2 | import {Popover} from "./Popover";
|
3 | 3 |
|
4 | 4 | @Component({
|
@@ -102,28 +102,31 @@ export class PopoverContent implements AfterViewInit, OnDestroy {
|
102 | 102 | // -------------------------------------------------------------------------
|
103 | 103 |
|
104 | 104 | constructor(protected element: ElementRef,
|
105 |
| - protected cdr: ChangeDetectorRef) { |
| 105 | + protected cdr: ChangeDetectorRef, |
| 106 | + protected renderer: Renderer) { |
106 | 107 | }
|
107 | 108 |
|
108 | 109 | // -------------------------------------------------------------------------
|
109 | 110 | // Lifecycle callbacks
|
110 | 111 | // -------------------------------------------------------------------------
|
111 | 112 |
|
| 113 | + listenClickFunc: any; |
| 114 | + listenMouseFunc: any; |
112 | 115 | ngAfterViewInit(): void {
|
113 | 116 | if (this.closeOnClickOutside)
|
114 |
| - document.addEventListener("mousedown", this.onDocumentMouseDown); |
| 117 | + this.listenClickFunc = this.renderer.listenGlobal("document", "mousedown", (event: any) => this.onDocumentMouseDown(event)); |
115 | 118 | if (this.closeOnMouseOutside)
|
116 |
| - document.addEventListener("mouseover", this.onDocumentMouseDown); |
| 119 | + this.listenMouseFunc = this.renderer.listenGlobal("document", "mouseover", (event: any) => this.onDocumentMouseDown(event)); |
117 | 120 |
|
118 | 121 | this.show();
|
119 | 122 | this.cdr.detectChanges();
|
120 | 123 | }
|
121 | 124 |
|
122 | 125 | ngOnDestroy() {
|
123 | 126 | if (this.closeOnClickOutside)
|
124 |
| - document.removeEventListener("mousedown", this.onDocumentMouseDown); |
| 127 | + this.listenClickFunc(); |
125 | 128 | if (this.closeOnMouseOutside)
|
126 |
| - document.removeEventListener("mouseover", this.onDocumentMouseDown); |
| 129 | + this.listenMouseFunc(); |
127 | 130 | }
|
128 | 131 |
|
129 | 132 | // -------------------------------------------------------------------------
|
|
0 commit comments