import { Directive , HostListener , Input , Optional } from '@angular/core' ; import { Button } from '../button/button' ; import { MenuController } from '../app/menu-controller' ; import { Navbar } from '../toolbar/navbar' ; import { ViewController } from '../../navigation/view-controller' ; name description usage demo see {@link /docs/components#menus Menu Component Docs} see {@link ../../menu/Menu Menu API Docs} @ Directive ( { selector : '[menuToggle]' , host : { '[hidden]' : 'isHidden' } } ) export class MenuToggle { hidden @ Input ( ) menuToggle : string ; hidden private _isButton : boolean ; hidden private _inNavbar : boolean ; constructor ( private _menu , @ Optional ( ) private _viewCtrl , @ Optional ( ) private _button , @ Optional ( ) _navbar ) { this . _isButton = ! ! _button ; this . _inNavbar = ! ! _navbar ; } ngAfterContentInit ( ) { if ( this . _isButton ) { this . _button . _setClass ( 'menutoggle' , true ) ; } } hidden @ HostListener ( 'click' ) toggle ( ) { const menu = this . _menu . get ( this . menuToggle ) ; menu && menu . toggle ( ) ; } hidden get isHidden ( ) { const menu = this . _menu . get ( this . menuToggle ) ; if ( this . _inNavbar && this . _viewCtrl ) { if ( ! menu || ! menu . _canOpen ( ) ) { return true ; } if ( this . _viewCtrl . isFirst ( ) ) { return false ; } if ( menu ) { return ! menu . persistent ; } } return false ; } }