Skip to content

Commit e44be40

Browse files
committed
au-tab-panel tests
1 parent ebd6c34 commit e44be40

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import {AfterContentInit, ContentChild, Directive, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
1+
import {AfterContentInit, ContentChild, Directive, Input, OnInit, TemplateRef, ViewContainerRef, OnDestroy} from '@angular/core';
22
import {AuModalComponent} from "./au-modal.component";
33
import {AuModalService} from "./modal.service";
44

55
@Directive({
66
selector: '[auModalOpenOnClick]'
77
})
8-
export class AuModalOpenOnClickDirective implements OnInit {
8+
export class AuModalOpenOnClickDirective implements OnInit, OnDestroy {
99

1010

11+
elements: HTMLBaseElement[];
12+
1113
constructor(private templateRef: TemplateRef<any>,
1214
private viewContainer: ViewContainerRef,
1315
private modalService: AuModalService) {
@@ -20,28 +22,28 @@ export class AuModalOpenOnClickDirective implements OnInit {
2022

2123
}
2224

25+
ngOnDestroy() {
26+
this.elements.forEach(el => el.removeEventListener('click', this.clickHandler) );
27+
}
28+
2329
@Input()
2430
set auModalOpenOnClick(els) {
2531

26-
let elements: HTMLBaseElement[];
27-
2832
if (els.length) {
29-
elements = els;
33+
this.elements = els;
3034
}
3135
else {
32-
elements = [els];
36+
this.elements = [els];
3337
}
3438

35-
elements.forEach(el => {
36-
37-
el.addEventListener('click', (evt) => {
38-
this.viewContainer.clear();
39-
this.viewContainer.createEmbeddedView(this.templateRef);
40-
41-
} );
39+
this.elements.forEach(el => el.addEventListener('click', this.clickHandler));
40+
}
4241

43-
})
4442

45-
}
43+
clickHandler = (() => {
44+
this.viewContainer.clear();
45+
this.viewContainer.createEmbeddedView(this.templateRef);
46+
}).bind(this);
4647

4748
}
49+

0 commit comments

Comments
 (0)