accordionlink.directive.ts
838 Bytes
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 {
Directive, HostBinding, Inject, Input, OnInit, OnDestroy
} from '@angular/core';
import { AccordionDirective } from './accordion.directive';
@Directive({
selector: '[appAccordionLink]'
})
export class AccordionLinkDirective implements OnInit, OnDestroy {
@Input() public group: any;
@HostBinding('class.open')
@Input()
get open(): boolean {
return this._open;
}
set open(value: boolean) {
this._open = value;
if (value) {
this.nav.closeOtherLinks(this);
}
}
protected _open: boolean;
protected nav: AccordionDirective;
constructor(@Inject(AccordionDirective) nav: AccordionDirective) {
this.nav = nav;
}
ngOnInit(): any {
this.nav.addLink(this);
}
ngOnDestroy(): any {
this.nav.removeGroup(this);
}
toggle(): any {
this.open = !this.open;
}
}