import { Pipe , PipeTransform } from '@angular/core' ; /**
 * Pipe used in boolean expressions in a template to signify
 * that the pipe value argument is defined using the
 * transform() method.
 *
 * If the transform() argument is defined, then the method
 * will return true. However, if the argument to transform()
 * is a string and it can be trimmed to an empty string,
 * then false is returned. Also, if the argument to tranform()
 * is a string with a trimmed value of 'null' or 'undefined;,
 * then false is returned.
 *
 */ @ Pipe ( { name : 'isdefined' } ) export class IsDefinedPipe implements PipeTransform { param value param args return transform ( value , args ? ) { if ( typeof value === 'string' ) { return this . isDefinedString ( value ) ; } else if ( typeof value === 'number' ) { return this . isDefinedNumber ( value ) ; } else if ( value ) { return true ; } return false ; } private isDefinedString ( value ) { value = value . trim ( ) ; if ( value === 'null' ) { return false ; } else if ( value === 'undefined' ) { return false ; } else { if ( value ) { return true ; } } } private isDefinedNumber ( value ) { if ( value === 0 ) { return true ; } else { if ( value ) { return true ; } } } }