import { Directive , HostListener , Input , OnInit } from '@angular/core' ; import { ExpansionPanelDirective } from './expansion-panel.directive' ; example @ Directive ( { selector : '[gdExpansionTrigger]' , host : { 'class' : 'ExpansionTrigger' , '[class.ExpansionTrigger--triggered]' : 'panelOpen' , '[attr.aria-expanded]' : 'panelOpen || null' , } , } ) export class ExpansionTriggerDirective implements OnInit { @ Input ( 'gdExpansionTrigger' ) panel : ExpansionPanelDirective ; get panelOpen ( ) : boolean { return this . panel && this . panel . expanded ; } ngOnInit ( ) { if ( ! this . panel ) { throw new Error ( 'Cannot find provided expansion panel!' ) ; } } toggle ( ) { this . panel . expanded = ! this . panel . expanded ; } open ( ) { this . panel . expanded = true ; } close ( ) { this . panel . expanded = false ; } @ HostListener ( 'click' ) _handleClick ( ) { this . toggle ( ) ; } }