Skip to content

Commit 34a8a46

Browse files
committed
onClick must be below @HostListener to work
1 parent 1e60b7a commit 34a8a46

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-2-dropdown-multiselect",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "Customizable dropdown multiselect in Angular 2 with bootstrap css.",
55
"main": "src/multiselect-dropdown.ts",
66
"repository": {

src/multiselect-dropdown.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ export class MultiselectDropdown implements OnInit, DoCheck, ControlValueAccesso
8585
@Output() dropdownClosed = new EventEmitter();
8686

8787
@HostListener('document: click', ['$event.target'])
88+
onClick(target: HTMLElement) {
89+
let parentFound = false;
90+
while (target != null && !parentFound) {
91+
if (target === this.element.nativeElement) {
92+
parentFound = true;
93+
}
94+
target = target.parentElement;
95+
}
96+
if (!parentFound) {
97+
this.isVisible = false;
98+
}
99+
}
88100

89101
model: number[];
90102
title: string;
@@ -125,18 +137,6 @@ export class MultiselectDropdown implements OnInit, DoCheck, ControlValueAccesso
125137
this.title = this.texts.defaultTitle;
126138
}
127139

128-
onClick(target: HTMLElement) {
129-
let parentFound = false;
130-
while (target != null && !parentFound) {
131-
if (target === this.element.nativeElement) {
132-
parentFound = true;
133-
}
134-
target = target.parentElement;
135-
}
136-
if (!parentFound) {
137-
this.isVisible = false;
138-
}
139-
}
140140
onModelChange: Function = (_: any) => { };
141141
onModelTouched: Function = () => { };
142142

0 commit comments

Comments
 (0)