import { Directive } from '@angular/core' ; import { NG_VALIDATORS , Validator , AbstractControl } from '@angular/forms' ; @ Directive ( { selector : '[gbNonEmpty][ngModel]' , providers : [ { provide : NG_VALIDATORS , useExisting : NonEmptyValidatorDirective , multi : true } ] } ) export class NonEmptyValidatorDirective implements Validator { validate ( c ) { if ( c . value === null || c . value === undefined ) { return null ; } if ( c . value . trim ( ) === '' ) { return { gbNonEmpty : { valid : false } } ; } return null ; } }