license import { OnDestroy , Pipe , PipeTransform } from '@angular/core' ; import { DomSanitizer } from '@angular/platform-browser' ; @ Pipe ( { name : 'imageResolver' , } ) export class ImageResolverPipe implements PipeTransform , OnDestroy { objectUrl ? : string ; constructor ( private domSanitizer ) { } ngOnDestroy ( ) { if ( this . objectUrl ) { URL . revokeObjectURL ( this . objectUrl ) ; } } transform ( value ) { if ( this . objectUrl ) { URL . revokeObjectURL ( this . objectUrl ) ; this . objectUrl = undefined ; } if ( typeof value !== 'string' ) { this . objectUrl = URL . createObjectURL ( value ) ; return this . domSanitizer . bypassSecurityTrustUrl ( this . objectUrl ) ; } return value ; } }