import { Component , HostBinding , Input , OnInit , ViewEncapsulation } from '@angular/core' ; import { MenuItem , MenuService } from '@ngx-starter-kit/navigator' ; @ Component ( { selector : 'ngx-sidenav-item' , templateUrl : './sidenav-item.component.html' , styleUrls : [ './sidenav-item.component.scss' ] , encapsulation : ViewEncapsulation . None , } ) export class SidenavItemComponent implements OnInit { @ Input ( ) item : MenuItem ; @ HostBinding ( 'class.open' ) get isOpen ( ) { return this . menuService . isOpen ( this . item ) ; } @ HostBinding ( 'class.sidenav-item' ) sidenavItemClass = true ; constructor ( private menuService ) { } ngOnInit ( ) { } toggleDropdown ( ) { if ( this . item . children && this . item . children . length > 0 ) { this . menuService . toggleItemOpen ( this . item ) ; } } getSubItemsHeight ( ) { return this . getOpenSubItemsCount ( this . item ) * 48 + 'px' ; } private getOpenSubItemsCount ( item ) { let count = 0 ; if ( item . children && item . children . length > 0 && this . menuService . isOpen ( item ) ) { count += item . children . length ; item . children . forEach ( ( subItem ) => { count += this . getOpenSubItemsCount ( subItem ) ; } ) ; } return count ; } }