1
1
import { DOCUMENT } from '@angular/common' ;
2
2
import { Component , EventEmitter , HostBinding , Inject , Input , OnDestroy , OnInit , Output , Renderer2 } from '@angular/core' ;
3
+ import { Subscription } from 'rxjs' ;
4
+
3
5
import { sidebarCssClasses } from '../shared' ;
6
+ import { AppSidebarService } from './app-sidebar.service' ;
4
7
5
8
@Component ( {
6
9
selector : 'app-sidebar, cui-sidebar' ,
7
10
template : `<ng-content></ng-content>`
8
11
} )
9
12
export class AppSidebarComponent implements OnInit , OnDestroy {
13
+
14
+ private subscriptionEvents : Subscription ;
15
+ private _minimized = false ;
16
+
10
17
@Input ( ) compact : boolean ;
11
18
@Input ( ) display : any ;
12
19
@Input ( ) fixed : boolean ;
@@ -22,9 +29,9 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
22
29
this . _minimized = value ;
23
30
this . _updateMinimized ( value ) ;
24
31
this . minimizedChange . emit ( value ) ;
32
+ this . sidebarService . toggle ( { minimize : value } ) ;
25
33
}
26
34
}
27
- private _minimized = false ;
28
35
29
36
/**
30
37
* Emits whenever the minimized state of the sidebar changes.
@@ -36,7 +43,8 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
36
43
37
44
constructor (
38
45
@Inject ( DOCUMENT ) private document : any ,
39
- private renderer : Renderer2
46
+ private renderer : Renderer2 ,
47
+ private sidebarService : AppSidebarService
40
48
) {
41
49
}
42
50
@@ -45,9 +53,15 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
45
53
this . isCompact ( this . compact ) ;
46
54
this . isFixed ( this . fixed ) ;
47
55
this . isOffCanvas ( this . offCanvas ) ;
56
+ this . subscriptionEvents = this . sidebarService . events$ . subscribe ( action => {
57
+ if ( action . minimize === 'toggle' ) {
58
+ this . toggleMinimized ( ) ;
59
+ }
60
+ } ) ;
48
61
}
49
62
50
63
ngOnDestroy ( ) : void {
64
+ this . subscriptionEvents . unsubscribe ( ) ;
51
65
this . minimizedChange . complete ( ) ;
52
66
this . renderer . removeClass ( this . document . body , 'sidebar-fixed' ) ;
53
67
}
0 commit comments