Skip to content

Instantly share code, notes, and snippets.

@Bengejd
Created February 10, 2019 21:07
Show Gist options
  • Save Bengejd/93ed7151e833824241d2883c8252c554 to your computer and use it in GitHub Desktop.
Save Bengejd/93ed7151e833824241d2883c8252c554 to your computer and use it in GitHub Desktop.
Returns a provided default pipe if the initial value is falsy.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'default', pure: true})
export class DefaultPipe implements PipeTransform {
transform(value: any, defaultValue: any): any {
return value || defaultValue;
}
}
<img [src]="img.src | default:'https://source.unsplash.com/random/640x480'">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment