11import { DOCUMENT } from '@angular/common' ;
22import { Component , EventEmitter , HostBinding , Inject , Input , OnDestroy , OnInit , Output , Renderer2 } from '@angular/core' ;
3+ import { Subscription } from 'rxjs' ;
4+
35import { sidebarCssClasses } from '../shared' ;
6+ import { AppSidebarService } from './app-sidebar.service' ;
47
58@Component ( {
69 selector : 'app-sidebar, cui-sidebar' ,
710 template : `<ng-content></ng-content>`
811} )
912export class AppSidebarComponent implements OnInit , OnDestroy {
13+
14+ private subscriptionEvents : Subscription ;
15+ private _minimized = false ;
16+
1017 @Input ( ) compact : boolean ;
1118 @Input ( ) display : any ;
1219 @Input ( ) fixed : boolean ;
@@ -22,9 +29,9 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
2229 this . _minimized = value ;
2330 this . _updateMinimized ( value ) ;
2431 this . minimizedChange . emit ( value ) ;
32+ this . sidebarService . toggle ( { minimize : value } ) ;
2533 }
2634 }
27- private _minimized = false ;
2835
2936 /**
3037 * Emits whenever the minimized state of the sidebar changes.
@@ -36,7 +43,8 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
3643
3744 constructor (
3845 @Inject ( DOCUMENT ) private document : any ,
39- private renderer : Renderer2
46+ private renderer : Renderer2 ,
47+ private sidebarService : AppSidebarService
4048 ) {
4149 }
4250
@@ -45,9 +53,15 @@ export class AppSidebarComponent implements OnInit, OnDestroy {
4553 this . isCompact ( this . compact ) ;
4654 this . isFixed ( this . fixed ) ;
4755 this . isOffCanvas ( this . offCanvas ) ;
56+ this . subscriptionEvents = this . sidebarService . events$ . subscribe ( action => {
57+ if ( action . minimize === 'toggle' ) {
58+ this . toggleMinimized ( ) ;
59+ }
60+ } ) ;
4861 }
4962
5063 ngOnDestroy ( ) : void {
64+ this . subscriptionEvents . unsubscribe ( ) ;
5165 this . minimizedChange . complete ( ) ;
5266 this . renderer . removeClass ( this . document . body , 'sidebar-fixed' ) ;
5367 }
0 commit comments