Created
February 10, 2019 21:07
-
-
Save Bengejd/93ed7151e833824241d2883c8252c554 to your computer and use it in GitHub Desktop.
Returns a provided default pipe if the initial value is falsy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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