import { HostListener , HostBinding , Directive } from '@angular/core' ; @ Directive ( { selector : '[trimmed-input]' } ) export class TrimmedInput { @ HostBinding ( ) value : string ; @ HostListener ( "input" , [ "$event.target.value" ] ) onChange ( updatedValue ) { this . value = updatedValue . trim ( ) + '_' ; console . log ( this . value ) ; } constructor ( ) { this . value = 'foo' ; } }