import { Directive , OnInit , ElementRef , Renderer , Input } from '@angular/core' ; import { TranslateService , LangChangeEvent } from '@ngx-translate/core' ; @ Directive ( { selector : '[jhiActiveMenu]' } ) export class ActiveMenuDirective implements OnInit { @ Input ( ) jhiActiveMenu : string ; constructor ( private el , private renderer , private translateService ) { } ngOnInit ( ) { this . translateService . onLangChange . subscribe ( ( event ) => { this . updateActiveFlag ( event . lang ) ; } ) ; this . updateActiveFlag ( this . translateService . currentLang ) ; } updateActiveFlag ( selectedLanguage ) { if ( this . jhiActiveMenu === selectedLanguage ) { this . renderer . setElementClass ( this . el . nativeElement , 'active' , true ) ; } else { this . renderer . setElementClass ( this . el . nativeElement , 'active' , false ) ; } } }