import { Directive, ElementRef, HostListener, Injector, Input } from '@angular/core'; import { Format } from './classes'; import { noCallbackProvidedError, isNotFunctionError } from './exceptions'; @Directive({ selector: '[ang-format]', }) export class FormatDirective extends Format { @Input('ang-format') formatFn: Function; isFunction: boolean; notProvided: boolean; constructor(ref: ElementRef, injector: Injector){ super(ref,injector); } @HostListener('blur') onblur(){ if(this.notProvided)noCallbackProvidedError(); if(!this.isFunction)isNotFunctionError(this.formatFn); super.blurHandler(this.formatFn); } ngOnInit(){ this.isFunction = typeof this.formatFn === 'function'; this.notProvided = typeof this.formatFn === 'undefined'; } }