import { Directive , ElementRef , Input } from '@angular/core' ; @ Directive ( { selector : '[appClass]' } ) export class ClassDirective { constructor ( private element ) { } @ Input ( 'appClass' ) set classNames ( classObj ) { for ( let key in classObj ) { if ( classObj [ key ] ) { this . element . nativeElement . classList . add ( key ) ; } else { this . element . nativeElement . classList . remove ( key ) ; } } } }